imservices/imfeatureplugin/srcimdatamodel/imconversation/imconversationinfoimp.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2007 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:  MImConversationInfo API object implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "imconversationinfoimp.h"
       
    19 #include "ximpidentityimp.h"
       
    20 #include "ximprbufhelpers.h"
       
    21 //#include "ximpobjecthelpers.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS =============================
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CImConversationInfoImp::NewLC()
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 EXPORT_C CImConversationInfoImp* CImConversationInfoImp::NewLC()
       
    30     {
       
    31     CImConversationInfoImp* self = new( ELeave ) CImConversationInfoImp;
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     return self;
       
    35     }
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CImConversationInfoImp::NewL()
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CImConversationInfoImp* CImConversationInfoImp::NewL()
       
    43     {
       
    44     CImConversationInfoImp* self = NewLC();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CImConversationInfoImp::NewFromStreamLC()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CImConversationInfoImp )
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Implement supported interface access.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CImConversationInfoImp, MImConversationInfo )
       
    60 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    61 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CImConversationInfoImp, MImConversationInfo )
       
    62 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CImConversationInfoImp::~CImConversationInfoImp()
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CImConversationInfoImp::~CImConversationInfoImp()
       
    69     {
       
    70     iTextMessage.Close();
       
    71     if(iIdentity != NULL)
       
    72 	    {
       
    73 	    delete iIdentity;	
       
    74 	    }
       
    75     if(iRecipients != NULL)
       
    76     	{
       
    77     	iRecipients->Reset();
       
    78 		delete iRecipients;   
       
    79     	}
       
    80     
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CImConversationInfoImp::CImConversationInfoImp()
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CImConversationInfoImp::CImConversationInfoImp()
       
    88     {
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CImConversationInfoImp::ConstructL()
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CImConversationInfoImp::ConstructL()
       
    97     {
       
    98     iTextMessage.CreateL( 0 );
       
    99     iRecipients = new( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   100     iIdentity = CXIMPIdentityImp::NewLC();
       
   101     CleanupStack::Pop( iIdentity );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CImConversationInfoImp::ExternalizeL()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CImConversationInfoImp::ExternalizeL( RWriteStream& aStream ) const
       
   109     {
       
   110     iIdentity->ExternalizeL( aStream );
       
   111     XIMPRBuf16Helper::ExternalizeL( iTextMessage, aStream );
       
   112     for(TInt index=0;index<iRecipients->MdcaCount();index++)
       
   113 		{
       
   114 			RBuf16 userId;			
       
   115 			userId.Create(iRecipients->MdcaPoint(index));
       
   116 	    	XIMPRBuf16Helper::ExternalizeL(userId, aStream );
       
   117 	    	userId.Close();
       
   118 		}    
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CImConversationInfoImp::InternalizeL()
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C void CImConversationInfoImp::InternalizeL( RReadStream& aStream )
       
   126     {
       
   127     iIdentity->InternalizeL( aStream );
       
   128     XIMPRBuf16Helper::InternalizeL( iTextMessage, aStream ); 
       
   129     TInt length = 0;
       
   130     
       
   131     TRAP_IGNORE(length = aStream.ReadInt32L());    
       
   132     for ( TInt i = 0; i < length; i++ )
       
   133         {
       
   134         	RBuf16 userId; 	
       
   135    			XIMPRBuf16Helper::GrowIfNeededL( userId, length );
       
   136    			aStream.ReadL( userId, length );
       
   137 			iRecipients->AppendL(userId);
       
   138 			userId.Close();
       
   139 			TRAPD(leavecode,length = aStream.ReadInt32L());
       
   140 			if(leavecode != KErrNone) // if end of the Stream leavecode = KErrEof(-25)
       
   141    				break;
       
   142 		} 
       
   143     }
       
   144   
       
   145     
       
   146 // ---------------------------------------------------------------------------
       
   147 // From MImConversationInfo class.
       
   148 // CImConversationInfoImp::GroupId()
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 const MXIMPIdentity& CImConversationInfoImp::MessageId() const
       
   152     {
       
   153     return *iIdentity;
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // From MImConversationInfo class.
       
   159 // CImConversationInfoImp::TextMessage()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 const TDesC16& CImConversationInfoImp::TextMessage() const
       
   163     {
       
   164     return iTextMessage;
       
   165     }
       
   166     
       
   167 // ---------------------------------------------------------------------------
       
   168 // From MImConversationInfo class.
       
   169 // CImConversationInfoImp::RecipientL() 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 const MDesCArray& CImConversationInfoImp::RecipientL() const
       
   173     {
       
   174     return *iRecipients;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // From MImConversationInfo class.
       
   179 // CImConversationInfoImp::SetMessageIdL()
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CImConversationInfoImp::SetMessageIdL( MXIMPIdentity* aIdentity )
       
   183     {
       
   184     CXIMPIdentityImp* identityImp =
       
   185     TXIMPGetImpClassOrPanic< CXIMPIdentityImp>::From( *aIdentity );
       
   186 
       
   187     delete iIdentity;
       
   188     iIdentity = identityImp; 
       
   189     }
       
   190   
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // From MImConversationInfo class.
       
   194 // CImConversationInfoImp::SetTextMessageL()
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CImConversationInfoImp::SetTextMessageL( 
       
   198     const TDesC16& aTextMessage )
       
   199     {
       
   200     HBufC16* TextMessageBuf = aTextMessage.AllocL();
       
   201     iTextMessage.Close();
       
   202     iTextMessage.Assign( TextMessageBuf );
       
   203     }
       
   204  
       
   205 // ---------------------------------------------------------------------------
       
   206 // From MImConversationInfo class.
       
   207 // CImConversationInfoImp::SetRecipientL() recipient
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CImConversationInfoImp::SetRecipientL(const MDesCArray* aRecipients) 
       
   211     {
       
   212 	    for(TInt index=0;index<aRecipients->MdcaCount();index++)
       
   213 		{
       
   214 			HBufC* userId = aRecipients->MdcaPoint( index ).AllocL();
       
   215 			CleanupStack::PushL( userId );
       
   216 	    	iRecipients->AppendL(*userId);
       
   217 	    	CleanupStack::PopAndDestroy( userId ); // buf
       
   218 		}
       
   219     }
       
   220 // ---------------------------------------------------------------------------
       
   221 // CImConversationInfoImp::Identity
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 EXPORT_C const CXIMPIdentityImp& CImConversationInfoImp::IdentityImp() const
       
   225     {
       
   226     return *iIdentity;
       
   227     }
       
   228 // ---------------------------------------------------------------------------
       
   229 // CImConversationInfoImp::SetIdentityL()
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 EXPORT_C void CImConversationInfoImp::SetIdentity( CXIMPIdentityImp* aIdentity )
       
   233     {
       
   234     delete iIdentity;
       
   235     iIdentity = aIdentity;
       
   236     }
       
   237 // ---------------------------------------------------------------------------
       
   238 // CImConversationInfoImp::EqualsContent()
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TBool CImConversationInfoImp::EqualsContent( 
       
   242     const CXIMPApiDataObjBase& /*aOtherInstance*/ ) const
       
   243     {
       
   244     return ETrue;
       
   245     }
       
   246 
       
   247 // End of file