wvuing/wvuieng/EngSrc/CCAMessageContainer.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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:  Container class for messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CCAMessageContainer.h"
       
    20 #include "PublicEngineDefinitions.h"
       
    21 #include "CAUtils.h"
       
    22 #include "MCABufferMemoryHandler.h"
       
    23 #include "MCAMessageObserver.h"
       
    24 #include "MCAChatObserver.h"
       
    25 #include "CCAStorageManagerFactory.h"
       
    26 #include "MCAStoredGroups.h"
       
    27 #include "MCAStoredGroup.h"
       
    28 #include "MCALoggerWriteInterface.h"
       
    29 #include "ChatDebugPrint.h"
       
    30 #include "CCALoggerMessageHeader.h"
       
    31 #include "CALoggerManagerFactory.h"
       
    32 #include "MCAChatInterface.h"           // KSendBufferId
       
    33 #include "CCAMessageBase.h"
       
    34 #include "MCAStoredContact.h"
       
    35 #include "MCAStoredContacts.h"
       
    36 
       
    37 #include "impsbuilddefinitions.h"
       
    38 
       
    39 #include "ChatDebugAssert.h"
       
    40 
       
    41 #include <escapeutils.h>
       
    42 
       
    43 _LIT( KGroupIdPart, "/" );
       
    44 
       
    45 //-----------------------------------------------------------------------------
       
    46 // CCAMessageContainer::CCAMessageContainer
       
    47 // ( Other items commented in header )
       
    48 //-----------------------------------------------------------------------------
       
    49 CCAMessageContainer::CCAMessageContainer(
       
    50     MCABufferMemoryHandler& aMemoryHandler )
       
    51         : iMemoryHandler( aMemoryHandler ), iAddToContactAsked( EFalse )
       
    52     {
       
    53     }
       
    54 
       
    55 //-----------------------------------------------------------------------------
       
    56 // CCAMessageContainer::~CCAMessageContainer
       
    57 // ( Other items commented in header )
       
    58 //-----------------------------------------------------------------------------
       
    59 CCAMessageContainer::~CCAMessageContainer()
       
    60     {
       
    61     if ( iObserver )
       
    62         {
       
    63         iObserver->HandleMessageEvent( MCAMessageObserver::EChatDeleted );
       
    64         }
       
    65 
       
    66     for ( TInt a( 0 ); a < iMessageContainer.Count(); ++a )
       
    67         {
       
    68         if ( iMessageContainer[ a ]->DecreaseOwnerCount() )
       
    69             {
       
    70             delete iMessageContainer[ a ];
       
    71             }
       
    72         }
       
    73     iMessageContainer.Reset();
       
    74 
       
    75     NotifyContactForPending();
       
    76 
       
    77     delete iLogger;
       
    78     delete iServerAddress;
       
    79     delete iUserId;
       
    80     delete iTargetId;
       
    81     delete iScreenName;
       
    82     delete iDecodedTargetId;
       
    83     }
       
    84 
       
    85 //-----------------------------------------------------------------------------
       
    86 // CCAMessageContainer::NewL
       
    87 // ( Other items commented in header )
       
    88 //-----------------------------------------------------------------------------
       
    89 CCAMessageContainer* CCAMessageContainer::NewL(
       
    90     const TDesC& aServerAddress,
       
    91     const TDesC& aUserId,
       
    92     const TDesC& aTargetId,
       
    93     MCABufferMemoryHandler& aMemoryHandler,
       
    94     TContainerType aType )
       
    95     {
       
    96     CCAMessageContainer* self = CCAMessageContainer::NewLC( aServerAddress,
       
    97                                                             aUserId,
       
    98                                                             aTargetId,
       
    99                                                             aMemoryHandler,
       
   100                                                             aType );
       
   101     CleanupStack::Pop( self );
       
   102     return self;
       
   103     }
       
   104 
       
   105 //-----------------------------------------------------------------------------
       
   106 // CCAMessageContainer::NewLC
       
   107 // ( Other items commented in header )
       
   108 //-----------------------------------------------------------------------------
       
   109 CCAMessageContainer* CCAMessageContainer::NewLC(
       
   110     const TDesC& aServerAddress,
       
   111     const TDesC& aUserId,
       
   112     const TDesC& aTargetId,
       
   113     MCABufferMemoryHandler& aMemoryHandler,
       
   114     TContainerType aType )
       
   115     {
       
   116     CCAMessageContainer* self =
       
   117         new ( ELeave ) CCAMessageContainer( aMemoryHandler );
       
   118     CleanupStack::PushL( self );
       
   119     self->ConstructL( aServerAddress, aUserId, aTargetId, aType );
       
   120     return self;
       
   121     }
       
   122 
       
   123 //-----------------------------------------------------------------------------
       
   124 // CCAMessageContainer::ConstructL
       
   125 // ( Other items commented in header )
       
   126 //-----------------------------------------------------------------------------
       
   127 void CCAMessageContainer::ConstructL( const TDesC& aServerAddress,
       
   128                                       const TDesC& aUserId,
       
   129                                       const TDesC& aTargetId,
       
   130                                       TContainerType aType )
       
   131     {
       
   132     iServerAddress = aServerAddress.AllocL();
       
   133     iUserId = aUserId.AllocL();
       
   134     iTargetId = aTargetId.AllocL();
       
   135     iDecodedTargetId = EscapeUtils::EscapeDecodeL( *iTargetId );
       
   136     iScreenName = KNullDesC().AllocL();
       
   137 
       
   138     ResolveType( aType );
       
   139 
       
   140     iLogger = CALoggerManagerFactory::WriteInstanceL();
       
   141     }
       
   142 
       
   143 //-----------------------------------------------------------------------------
       
   144 // CCAMessageContainer::UnreadCount
       
   145 // ( Other items commented in header )
       
   146 //-----------------------------------------------------------------------------
       
   147 TInt CCAMessageContainer::UnreadCount(
       
   148     MCAMessagesReadInterface::TUnreadFilter aUnreadFilter ) const
       
   149     {
       
   150     TInt countOfAll = iMessageContainer.Count();
       
   151     TInt unreadCount = countOfAll - iUnreadOffset;
       
   152     if ( aUnreadFilter != EUnreadAll )
       
   153         {
       
   154         for ( TInt a = countOfAll - 1; a >= iUnreadOffset; --a )
       
   155             {
       
   156             if ( iMessageContainer[ a ]->MessagerType() == MCAMessage::EMessageSent )
       
   157                 {
       
   158                 unreadCount--;
       
   159                 }
       
   160             }
       
   161         }
       
   162     return unreadCount;
       
   163     }
       
   164 
       
   165 //-----------------------------------------------------------------------------
       
   166 // CCAMessageContainer::MessageCount
       
   167 // ( Other items commented in header )
       
   168 //-----------------------------------------------------------------------------
       
   169 TInt CCAMessageContainer::MessageCount() const
       
   170     {
       
   171     // Offset is index to first unread message. It is exatly same as count of
       
   172     // read messages.
       
   173     return iUnreadOffset;
       
   174     }
       
   175 
       
   176 //-----------------------------------------------------------------------------
       
   177 // CCAMessageContainer::Read
       
   178 // ( Other items commented in header )
       
   179 //-----------------------------------------------------------------------------
       
   180 void CCAMessageContainer::Read( TReadType aReadType, TInt aAmount /* = 0 */ )
       
   181     {
       
   182     TInt messageCount( iMessageContainer.Count() );
       
   183     TInt originalUnreadCount = UnreadCount( );
       
   184 
       
   185     switch ( aReadType )
       
   186         {
       
   187         case EReadAll:
       
   188             iUnreadOffset = messageCount;
       
   189             break;
       
   190         case EReadAmount:
       
   191             iUnreadOffset += aAmount;
       
   192             break;
       
   193         case EReadOne:
       
   194             ++iUnreadOffset;
       
   195             break;
       
   196         default:
       
   197             __CHAT_ASSERT_DEBUG( EFalse );
       
   198             return;
       
   199         }
       
   200 
       
   201     // Cannot be more than messageCount
       
   202     if ( iUnreadOffset > messageCount )
       
   203         {
       
   204         iUnreadOffset = messageCount;
       
   205         }
       
   206 
       
   207     // Inform observers only if unreadcount is changed.
       
   208     if ( originalUnreadCount != UnreadCount() )
       
   209         {
       
   210         if ( iChatObserver )
       
   211             {
       
   212             iChatObserver->HandleChatEvent(
       
   213                 MCAChatObserver::EUnreadCountChanged );
       
   214             }
       
   215         }
       
   216 
       
   217     NotifyContactForPending();
       
   218     }
       
   219 
       
   220 //-----------------------------------------------------------------------------
       
   221 // CCAMessageContainer::Message
       
   222 // ( Other items commented in header )
       
   223 //-----------------------------------------------------------------------------
       
   224 MCAMessage& CCAMessageContainer::Message( TInt aIndex ) const
       
   225     {
       
   226     __CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < MessageCount() );
       
   227     return *iMessageContainer[ aIndex ];
       
   228     }
       
   229 
       
   230 //-----------------------------------------------------------------------------
       
   231 // CCAMessageContainer::ReadNextUnread
       
   232 // ( Other items commented in header )
       
   233 //-----------------------------------------------------------------------------
       
   234 MCAMessage& CCAMessageContainer::ReadNextUnread()
       
   235     {
       
   236     __CHAT_ASSERT_DEBUG( UnreadCount() != 0 );
       
   237     Read( EReadOne );
       
   238     return *iMessageContainer[ MessageCount() - 1 ];
       
   239     }
       
   240 
       
   241 //-----------------------------------------------------------------------------
       
   242 // CCAMessageContainer::ReadUnreadFromIndex
       
   243 // ( Other items commented in header )
       
   244 //-----------------------------------------------------------------------------
       
   245 MCAMessage& CCAMessageContainer::ReadUnreadFromIndex( TInt aIndex )
       
   246     {
       
   247     __CHAT_ASSERT_DEBUG( UnreadCount() != 0 );
       
   248     __CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < iMessageContainer.Count() );
       
   249     Read( EReadOne );
       
   250     return *iMessageContainer[aIndex];
       
   251     }
       
   252 
       
   253 //-----------------------------------------------------------------------------
       
   254 // CCAMessageContainer::SetObserver
       
   255 // ( Other items commented in header )
       
   256 //-----------------------------------------------------------------------------
       
   257 void CCAMessageContainer::SetObserver( MCAMessageObserver* aObserver )
       
   258     {
       
   259     iObserver = aObserver;
       
   260     }
       
   261 
       
   262 //-----------------------------------------------------------------------------
       
   263 // CCAMessageContainer::SetObserver
       
   264 // ( Other items commented in header )
       
   265 //-----------------------------------------------------------------------------
       
   266 TPtrC CCAMessageContainer::Name() const
       
   267     {
       
   268     // Resolve name
       
   269     switch ( iContainerType )
       
   270         {
       
   271         case EChatContainer:
       
   272             {
       
   273             return CAUtils::DisplayId( *iTargetId );
       
   274             }
       
   275         case EGroupContainer:
       
   276             {
       
   277             MCAStoredGroup* group = NULL;
       
   278             TRAPD( err, group =
       
   279                        CCAStorageManagerFactory::GroupListInterfaceL()->FindGroup(
       
   280                            *iTargetId ) );
       
   281             if ( err != KErrNone )
       
   282                 {
       
   283                 CActiveScheduler::Current()->Error( err );
       
   284                 }
       
   285             if ( group )
       
   286                 {
       
   287                 return group->GroupName();
       
   288                 }
       
   289             return *iTargetId;
       
   290             }
       
   291         default:
       
   292             {
       
   293             __CHAT_ASSERT_DEBUG( EFalse );
       
   294             return KNullDesC();
       
   295             }
       
   296         }
       
   297     }
       
   298 
       
   299 //-----------------------------------------------------------------------------
       
   300 // CCAMessageContainer::DeleteMessage
       
   301 // ( Other items commented in header )
       
   302 //-----------------------------------------------------------------------------
       
   303 void CCAMessageContainer::DeleteMessage( TInt aIndex )
       
   304     {
       
   305     MCAMessage* target = &Message( aIndex );
       
   306     iMessageContainer.Remove( aIndex );
       
   307     iContainerSizeInBytes -= target->SizeInBytes();
       
   308     --iUnreadOffset;
       
   309 
       
   310     if ( iObserver )
       
   311         {
       
   312         iObserver->HandleMessageEvent( MCAMessageObserver::EMessageDeleted,
       
   313                                        aIndex );
       
   314         }
       
   315 
       
   316     if ( target->DecreaseOwnerCount() )
       
   317         {
       
   318         delete target;
       
   319         }
       
   320     }
       
   321 
       
   322 //-----------------------------------------------------------------------------
       
   323 // CCAMessageContainer::AppendL
       
   324 // ( Other items commented in header )
       
   325 //-----------------------------------------------------------------------------
       
   326 void CCAMessageContainer::AppendL( MCAMessage* aMessage, TBool aSharedOwnership )
       
   327     {
       
   328     if ( !aMessage )
       
   329         {
       
   330         User::Leave( KErrArgument );
       
   331         }
       
   332 
       
   333     if ( !aSharedOwnership )
       
   334         {
       
   335         CleanupDeletePushL( aMessage );
       
   336         }
       
   337 
       
   338     // Check memory status
       
   339     // if failes, leave with KErrNoMemory
       
   340     if ( !iMemoryHandlingLocked )
       
   341         {
       
   342         if ( !iMemoryHandler.FreeMemoryIfNeededL( aMessage->SizeInBytes() ) )
       
   343             {
       
   344             User::Leave( KErrNoMemory );
       
   345             }
       
   346         }
       
   347 
       
   348     iMessageContainer.AppendL( aMessage );
       
   349     iContainerSizeInBytes += aMessage->SizeInBytes();
       
   350 
       
   351     if ( !aSharedOwnership )
       
   352         {
       
   353         CleanupStack::Pop( aMessage );
       
   354         }
       
   355 
       
   356     aMessage->IncreaseOwnerCount();
       
   357 
       
   358     aMessage->SetContainerInfo( this );
       
   359 
       
   360     // Record message if logging is on
       
   361     if ( iLogger->IsLoggingOn() )
       
   362         {
       
   363         iLogger->MakeLogL( aMessage->LoggerMessage() );
       
   364         }
       
   365 
       
   366     CHAT_DP( D_CHAT_LIT( "Address: %s, UserId: %s, Sender %s, Recipient %s" ),
       
   367              &aMessage->ServerAddress(),
       
   368              &aMessage->UserId(),
       
   369              &aMessage->Sender(),
       
   370              &aMessage->Recipient() );
       
   371 
       
   372     CCAMessageBase* messageBase = static_cast< CCAMessageBase* >( aMessage );
       
   373     messageBase->SetContentProcessObserver( this );
       
   374 
       
   375     if ( iObserver )
       
   376         {
       
   377         iObserver->HandleMessageEvent( MCAMessageObserver::ENewMessage );
       
   378         }
       
   379 
       
   380     if ( iChatObserver )
       
   381         {
       
   382         iChatObserver->HandleChatEvent( MCAChatObserver::EUnreadCountChanged,
       
   383                                         aMessage );
       
   384         }
       
   385 
       
   386     NotifyContactForPending();
       
   387     }
       
   388 
       
   389 //-----------------------------------------------------------------------------
       
   390 // CCAMessageContainer::SetScreenNameL
       
   391 // ( Other items commented in header )
       
   392 //-----------------------------------------------------------------------------
       
   393 void CCAMessageContainer::SetScreenNameL( const TDesC& aScreenName )
       
   394     {
       
   395     HBufC* newSn = aScreenName.AllocL();
       
   396     delete iScreenName;
       
   397     iScreenName = newSn;
       
   398     }
       
   399 
       
   400 //-----------------------------------------------------------------------------
       
   401 // CCAMessageContainer::OwnScreenName
       
   402 // ( Other items commented in header )
       
   403 //-----------------------------------------------------------------------------
       
   404 const TDesC& CCAMessageContainer::OwnScreenName() const
       
   405     {
       
   406     return ScreenName();
       
   407     }
       
   408 
       
   409 //-----------------------------------------------------------------------------
       
   410 // CCAMessageContainer::LockBufferMemoryHandling
       
   411 // ( Other items commented in header )
       
   412 //-----------------------------------------------------------------------------
       
   413 //
       
   414 void CCAMessageContainer::LockBufferMemoryHandling( TBool aLocked )
       
   415     {
       
   416     iMemoryHandlingLocked = aLocked;
       
   417     }
       
   418 
       
   419 //-----------------------------------------------------------------------------
       
   420 // CCAMessageContainer::ServerAddress
       
   421 // ( Other items commented in header )
       
   422 //-----------------------------------------------------------------------------
       
   423 //
       
   424 TTime CCAMessageContainer::Time()
       
   425     {
       
   426     TTime time = Time::NullTTime();
       
   427     TInt count = iMessageContainer.Count();
       
   428     if ( count == 0 )
       
   429         {
       
   430         // no messages, return null
       
   431         return time;
       
   432         }
       
   433     return iMessageContainer[count - 1]->TimeStamp();
       
   434     }
       
   435 
       
   436 //-----------------------------------------------------------------------------
       
   437 // CCAMessageContainer::ServerAddress
       
   438 // ( Other items commented in header )
       
   439 //-----------------------------------------------------------------------------
       
   440 const TDesC& CCAMessageContainer::ServerAddress() const
       
   441     {
       
   442     if ( !iServerAddress )
       
   443         {
       
   444         return KNullDesC;
       
   445         }
       
   446     return *iServerAddress;
       
   447     }
       
   448 
       
   449 //-----------------------------------------------------------------------------
       
   450 // CCAMessageContainer::UserId
       
   451 // ( Other items commented in header )
       
   452 //-----------------------------------------------------------------------------
       
   453 const TDesC& CCAMessageContainer::UserId() const
       
   454     {
       
   455     if ( !iUserId )
       
   456         {
       
   457         return KNullDesC;
       
   458         }
       
   459     return *iUserId;
       
   460     }
       
   461 
       
   462 //-----------------------------------------------------------------------------
       
   463 // CCAMessageContainer::Target
       
   464 // ( Other items commented in header )
       
   465 //-----------------------------------------------------------------------------
       
   466 const TDesC& CCAMessageContainer::Target() const
       
   467     {
       
   468     if ( !iTargetId )
       
   469         {
       
   470         return KNullDesC;
       
   471         }
       
   472     return *iTargetId;
       
   473     }
       
   474 
       
   475 //-----------------------------------------------------------------------------
       
   476 // CCAMessageContainer::ScreenName
       
   477 // ( Other items commented in header )
       
   478 //-----------------------------------------------------------------------------
       
   479 const TDesC& CCAMessageContainer::ScreenName() const
       
   480     {
       
   481     if ( iScreenName )
       
   482         {
       
   483         return *iScreenName;
       
   484         }
       
   485     return KNullDesC;
       
   486     }
       
   487 
       
   488 //-----------------------------------------------------------------------------
       
   489 // CCAMessageContainer::SetAddToContactAsked
       
   490 // ( Other items commented in header )
       
   491 //-----------------------------------------------------------------------------
       
   492 void CCAMessageContainer::SetAddToContactAsked( TBool aIsAsked )
       
   493     {
       
   494     iAddToContactAsked = aIsAsked;
       
   495     }
       
   496 
       
   497 //-----------------------------------------------------------------------------
       
   498 // CCAMessageContainer::IsAddToContactAsked
       
   499 // ( Other items commented in header )
       
   500 //-----------------------------------------------------------------------------
       
   501 TBool CCAMessageContainer::IsAddToContactAsked() const
       
   502     {
       
   503     return iAddToContactAsked;
       
   504     }
       
   505 
       
   506 //-----------------------------------------------------------------------------
       
   507 // CCAMessageContainer::Target
       
   508 // ( Other items commented in header )
       
   509 //-----------------------------------------------------------------------------
       
   510 void CCAMessageContainer::HandleProcessingComplete(
       
   511     MCAContentProcessor& /* aProcessor */,
       
   512     MCAMessage& aMessage, TInt /* aStatus */ )
       
   513     {
       
   514     TInt count( iMessageContainer.Count() );
       
   515     if ( !iObserver ) // No observer. No need of informing anything.
       
   516         {
       
   517         return;
       
   518         }
       
   519     for ( TInt index( count - 1 ); index >= 0; --index )
       
   520         {
       
   521         if ( iMessageContainer[ index ] == &aMessage )
       
   522             {
       
   523             iObserver->HandleMessageEvent( MCAMessageObserver::EMessageChanged,
       
   524                                            index );
       
   525             return;
       
   526             }
       
   527         }
       
   528     }
       
   529 
       
   530 //-----------------------------------------------------------------------------
       
   531 // CCAMessageContainer::OrderUid
       
   532 // ( Other items commented in header )
       
   533 //-----------------------------------------------------------------------------
       
   534 TInt CCAMessageContainer::OrderUid( const CCAMessageContainer& aSourceA,
       
   535                                     const CCAMessageContainer& aSourceB )
       
   536     {
       
   537     // First Server
       
   538     // Then UserId
       
   539     // Last Target
       
   540 
       
   541 
       
   542     /*	TInt res = CAUtils::NeutralCompare( aSourceA.ServerAddress(),
       
   543                                             aSourceB.ServerAddress() );
       
   544     	if( res != 0 )
       
   545     	    {
       
   546     	    return res;
       
   547     	    }
       
   548     	res = CAUtils::NeutralCompare( aSourceA.UserId(), aSourceB.UserId() );
       
   549     	if( res != 0 )
       
   550     	    {
       
   551     	    return res;
       
   552     	    }*/
       
   553 
       
   554     return CAUtils::NeutralCompare( aSourceA.ComparableTarget(),
       
   555                                     aSourceB.ComparableTarget() );
       
   556     }
       
   557 
       
   558 //-----------------------------------------------------------------------------
       
   559 // CCAMessageContainer::ContainerType
       
   560 // ( Other items commented in header )
       
   561 //-----------------------------------------------------------------------------
       
   562 MCAMessagesReadInterface::TContainerType CCAMessageContainer::ContainerType() const
       
   563     {
       
   564     return iContainerType;
       
   565     }
       
   566 
       
   567 //-----------------------------------------------------------------------------
       
   568 // CCAMessageContainer::ResolveType
       
   569 // ( Other items commented in header )
       
   570 //-----------------------------------------------------------------------------
       
   571 void CCAMessageContainer::ChangeIdL( const TDesC& aServerAddress,
       
   572                                      const TDesC& aUserId,
       
   573                                      const TDesC& aTargetId,
       
   574                                      TContainerType aType )
       
   575     {
       
   576     HBufC* newServer = aServerAddress.AllocLC();
       
   577     HBufC* newUser = aUserId.AllocLC();
       
   578     HBufC* newTarget = aTargetId.AllocLC();
       
   579     HBufC* newDecoded = EscapeUtils::EscapeDecodeL( *newTarget );
       
   580     CleanupStack::Pop( 3, newServer );
       
   581 
       
   582     delete iServerAddress;
       
   583     delete iUserId;
       
   584     delete iTargetId;
       
   585     delete iDecodedTargetId;
       
   586 
       
   587     iServerAddress = newServer;
       
   588     iUserId = newUser;
       
   589     iTargetId = newTarget;
       
   590     iDecodedTargetId = newDecoded;
       
   591 
       
   592     ResolveType( aType );
       
   593     }
       
   594 
       
   595 //-----------------------------------------------------------------------------
       
   596 // CCAMessageContainer::ResolveType
       
   597 // ( Other items commented in header )
       
   598 //-----------------------------------------------------------------------------
       
   599 const TDesC& CCAMessageContainer::MessageRecipient( TInt aOperationCode,
       
   600                                                     TInt& aStatus ) const
       
   601     {
       
   602     TInt index = FindIndex( aOperationCode );
       
   603     if ( index >= 0 )
       
   604         {
       
   605         aStatus = KErrNone;
       
   606         return iMessageContainer[ index ]->Recipient();
       
   607         }
       
   608     aStatus = index;
       
   609     return KNullDesC;
       
   610     }
       
   611 
       
   612 //-----------------------------------------------------------------------------
       
   613 // CCAMessageContainer::ResolveType
       
   614 // ( Other items commented in header )
       
   615 //-----------------------------------------------------------------------------
       
   616 void CCAMessageContainer::SetChatObserver( MCAChatObserver* aObserver )
       
   617     {
       
   618     iChatObserver = aObserver;
       
   619     }
       
   620 
       
   621 //-----------------------------------------------------------------------------
       
   622 // CCAMessageContainer::ResolveType
       
   623 // ( Other items commented in header )
       
   624 //-----------------------------------------------------------------------------
       
   625 void CCAMessageContainer::ResolveType( TContainerType aType )
       
   626     {
       
   627     if ( aType != ENoneContainer )
       
   628         {
       
   629         iContainerType = aType;
       
   630         }
       
   631     else if ( iTargetId->Compare( KSendBufferId ) == 0
       
   632               || iTargetId->Compare( KLoggerBufferId ) == 0 )
       
   633         {
       
   634         iContainerType = ESendContainer;
       
   635         }
       
   636     else if ( iTargetId->FindC( KGroupIdPart ) == KErrNotFound )
       
   637         {
       
   638         iContainerType = EChatContainer;
       
   639         }
       
   640     else
       
   641         {
       
   642         iContainerType = EGroupContainer;
       
   643         }
       
   644     }
       
   645 
       
   646 //-----------------------------------------------------------------------------
       
   647 // CCAMessageContainer::StartLoggingL
       
   648 // ( Other items commented in header )
       
   649 //-----------------------------------------------------------------------------
       
   650 void CCAMessageContainer::StartLoggingL( const TDesC& aLogFilename )
       
   651     {
       
   652     CHAT_DP_FUNC_ENTER( "StartLoggingL" );
       
   653     __CHAT_ASSERT_DEBUG( iLogger );
       
   654 
       
   655     if ( iLogger->IsLoggingOn() )
       
   656         {
       
   657         User::Leave( KErrInUse );
       
   658         }
       
   659 
       
   660     TChatType type = ( iContainerType == EGroupContainer )
       
   661                      ? EGroupChat : EPTOPChat;
       
   662     //Create new headermessage for history file.
       
   663     CCALoggerMessageHeader* file =
       
   664         CCALoggerMessageHeader::NewL(	aLogFilename,
       
   665                                       Name(),
       
   666                                       type );
       
   667     //Start logging. The ownership of the file is transferred
       
   668     iLogger->StartLoggingL( file );
       
   669 
       
   670     // Flush already got messages to logfile.
       
   671     if ( iLogger->IsLoggingOn() )
       
   672         {
       
   673         // Write the contents of message buffer to log
       
   674         TInt count( iMessageContainer.Count() );
       
   675         for ( TInt a( 0 ); a < count; ++a )
       
   676             {
       
   677             iLogger->MakeLogL( iMessageContainer[ a ]->LoggerMessage() );
       
   678             }
       
   679         }
       
   680     }
       
   681 
       
   682 //-----------------------------------------------------------------------------
       
   683 // CCAMessageContainer::EndLoggingL
       
   684 // ( Other items commented in header )
       
   685 //-----------------------------------------------------------------------------
       
   686 void CCAMessageContainer::EndLoggingL()
       
   687     {
       
   688     CHAT_DP_FUNC_ENTER( "EndLoggingL" );
       
   689 
       
   690     //If logging is not on. we do not call endlogging.
       
   691     //Endlogging will leave with KErrNotReady if we call it without
       
   692     //logging on.
       
   693     if ( !iLogger->IsLoggingOn() )
       
   694         {
       
   695         CHAT_DP_FUNC_DONE( "EndLoggingL" );
       
   696         return;
       
   697         }
       
   698 
       
   699     //End logging.
       
   700     iLogger->EndLoggingL();
       
   701     CHAT_DP_FUNC_DONE( "EndLoggingL" );
       
   702     }
       
   703 
       
   704 //-----------------------------------------------------------------------------
       
   705 // CCAMessageContainer::IsLoggingL
       
   706 // ( Other items commented in header )
       
   707 //-----------------------------------------------------------------------------
       
   708 TBool CCAMessageContainer::IsLoggingOn() const
       
   709     {
       
   710     return iLogger->IsLoggingOn();
       
   711     }
       
   712 
       
   713 //-----------------------------------------------------------------------------
       
   714 // CCAMessageContainer::FindIndex
       
   715 // ( Other items commented in header )
       
   716 //-----------------------------------------------------------------------------
       
   717 TInt CCAMessageContainer::FindIndex( TInt aOperationCode ) const
       
   718     {
       
   719     // Use count of all messages when finding with operationcode.
       
   720     TInt count( iMessageContainer.Count() );
       
   721     for ( TInt a( 0 ); a < count; ++a )
       
   722         {
       
   723         if ( iMessageContainer[ a ]->OperationCode() == aOperationCode )
       
   724             {
       
   725             return a;
       
   726             }
       
   727         }
       
   728     return KErrNotFound;
       
   729     }
       
   730 
       
   731 //-----------------------------------------------------------------------------
       
   732 // CCAMessageContainer::FindIndex
       
   733 // ( Other items commented in header )
       
   734 //-----------------------------------------------------------------------------
       
   735 TInt CCAMessageContainer::FindIndex( MCAMessage& aMessage ) const
       
   736     {
       
   737     // Use count of all messages when finding with operationcode.
       
   738     TInt count( iMessageContainer.Count() );
       
   739     for ( TInt a( 0 ); a < count; ++a )
       
   740         {
       
   741         if ( iMessageContainer[ a ] == &aMessage )
       
   742             {
       
   743             return a;
       
   744             }
       
   745         }
       
   746     return KErrNotFound;
       
   747     }
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CCAMessageContainer::TargetId
       
   751 // ( Other items commented in header )
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 MCAMessageContainerInfo& CCAMessageContainer::TargetId()
       
   755     {
       
   756     return *this;
       
   757     }
       
   758 
       
   759 
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CCAMessageContainer::Lock
       
   763 // locks messagecontainer if needed.
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 void CCAMessageContainer::Lock( TBool aLocked )
       
   767     {
       
   768     iLocked = aLocked;
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CCAMessageContainer::MakeLogL
       
   773 // Tries to make log if possible.
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CCAMessageContainer::MakeLogL( MCALoggerMessage& aMessage )
       
   777     {
       
   778     CHAT_DP_FUNC_ENTER( "MakeLogL" );
       
   779     if ( iLogger->IsLoggingOn() )
       
   780         {
       
   781         TRAPD( ret, iLogger->MakeLogL( aMessage ) )
       
   782         if ( ret != KErrNone )
       
   783             {
       
   784             TInt ignore;
       
   785             TRAP( ignore, iLogger->EndLoggingL() )
       
   786             CActiveScheduler::Current()->Error( ret );
       
   787             }
       
   788         }
       
   789     CHAT_DP_FUNC_DONE( "MakeLogL" );
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CCAMessageContainer::NotifyContactForPending
       
   794 // ( Other items commented in header )
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 void CCAMessageContainer::NotifyContactForPending() const
       
   798     {
       
   799     TInt ignore;
       
   800     TRAP( ignore,
       
   801           CCAStorageManagerFactory::ContactListInterfaceL()->
       
   802           SetPendingMessages( *iTargetId, UnreadCount(
       
   803                                   MCAMessagesReadInterface::EUnreadReceived ) ) );
       
   804     }
       
   805 
       
   806 // -----------------------------------------------------------------------------
       
   807 // CCAMessageContainer::ComparableTarget
       
   808 // ( Other items commented in header )
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 const TDesC& CCAMessageContainer::ComparableTarget() const
       
   812     {
       
   813     if ( !iDecodedTargetId )
       
   814         {
       
   815         return KNullDesC;
       
   816         }
       
   817     return *iDecodedTargetId;
       
   818     }
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CCAMessageContainer::AllMessagesCount
       
   822 // ( Other items commented in header )
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 TInt CCAMessageContainer::AllMessagesCount() const
       
   826     {
       
   827     return iMessageContainer.Count();
       
   828     }
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 // CCABufferManager::NotifyContactForPending
       
   832 // ( Other items commented in header )
       
   833 // -----------------------------------------------------------------------------
       
   834 //
       
   835 MCAMessage& CCAMessageContainer::MessageFromAll( TInt aIndex ) const
       
   836     {
       
   837     __CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < AllMessagesCount() );
       
   838     return *iMessageContainer[ aIndex ];
       
   839     }
       
   840 
       
   841 //-----------------------------------------------------------------------------
       
   842 // CCAMessageContainer::DeleteMessageFromAll
       
   843 // ( Other items commented in header )
       
   844 //-----------------------------------------------------------------------------
       
   845 //
       
   846 void CCAMessageContainer::DeleteMessageFromAll( TInt aIndex )
       
   847     {
       
   848     MCAMessage* target = &MessageFromAll( aIndex );
       
   849     iMessageContainer.Remove( aIndex );
       
   850     iContainerSizeInBytes -= target->SizeInBytes();
       
   851     if ( iUnreadOffset > aIndex )
       
   852         {
       
   853         --iUnreadOffset;
       
   854         }
       
   855 
       
   856     if ( iObserver )
       
   857         {
       
   858         iObserver->HandleMessageEvent( MCAMessageObserver::EMessageDeleted,
       
   859                                        aIndex );
       
   860         }
       
   861 
       
   862     if ( target->DecreaseOwnerCount() )
       
   863         {
       
   864         delete target;
       
   865         }
       
   866     }
       
   867 
       
   868 //-----------------------------------------------------------------------------
       
   869 // CCAMessageContainer::IsLocked
       
   870 // ( Other items commented in header )
       
   871 //-----------------------------------------------------------------------------
       
   872 //
       
   873 TBool CCAMessageContainer::IsLocked() const
       
   874     {
       
   875     return iLocked || iMemoryHandlingLocked;
       
   876     }
       
   877 
       
   878 //-----------------------------------------------------------------------------
       
   879 // CCAMessageContainer::ContainerSizeInBytes
       
   880 // ( Other items commented in header )
       
   881 //-----------------------------------------------------------------------------
       
   882 //
       
   883 TInt CCAMessageContainer::ContainerSizeInBytes() const
       
   884     {
       
   885     return iContainerSizeInBytes;
       
   886     }
       
   887 
       
   888 //fix - refer Ui Spec Approved Version 1.0 (Instant Messaging NG 001 151006.pdf)
       
   889 //Section 10.2.10 Pg 131 -
       
   890 //"In case user has saved the image already or sent it by himself,
       
   891 // this option(save) is not available."
       
   892 //-----------------------------------------------------------------------------
       
   893 // CCAMessageContainer::ReLoggingL
       
   894 // ( Other items commented in header )
       
   895 //-----------------------------------------------------------------------------
       
   896 //
       
   897 void CCAMessageContainer::ReLoggingL( MCALoggerMessageHeader& aFile )
       
   898     {
       
   899     CHAT_DP_FUNC_ENTER( "ReLoggingL" );
       
   900     __CHAT_ASSERT_DEBUG( iLogger );
       
   901 
       
   902     if ( iLogger->IsLoggingOn() )
       
   903         {
       
   904         User::Leave( KErrInUse );
       
   905         }
       
   906 
       
   907     //Start logging. The ownership of the file is transferred
       
   908     iLogger->ReLoggingL( aFile );
       
   909 
       
   910     // Flush already got messages to logfile.
       
   911     if ( iLogger->IsLoggingOn() )
       
   912         {
       
   913         // Write the contents of message buffer to log
       
   914         TInt count( iMessageContainer.Count() );
       
   915         for ( TInt a( 0 ); a < count; ++a )
       
   916             {
       
   917             iLogger->MakeLogL( iMessageContainer[ a ]->LoggerMessage() );
       
   918             }
       
   919         }
       
   920     }
       
   921 
       
   922 //-----------------------------------------------------------------------------
       
   923 // CCAMessageContainer::EndReLoggingL
       
   924 // ( Other items commented in header )
       
   925 //-----------------------------------------------------------------------------
       
   926 void CCAMessageContainer::EndReLoggingL()
       
   927     {
       
   928     CHAT_DP_FUNC_ENTER( "EndReLoggingL" );
       
   929 
       
   930     //If logging is not on. we do not call endlogging.
       
   931     //Endlogging will leave with KErrNotReady if we call it without
       
   932     //logging on.
       
   933     if ( !iLogger->IsLoggingOn() )
       
   934         {
       
   935         CHAT_DP_FUNC_DONE( "EndReLoggingL" );
       
   936         return;
       
   937         }
       
   938 
       
   939     //End logging.
       
   940     iLogger->EndReLogging();
       
   941     CHAT_DP_FUNC_DONE( "EndReLoggingL" );
       
   942     }
       
   943 
       
   944 
       
   945 // end of file