wvuing/wvuiprocess/Src/IMMessageUtilsPC.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:  Utils for message handling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "IMMessageUtilsPC.h"
       
    22 #include	"ChatDebugPrint.h"
       
    23 
       
    24 #include    "imutils.h"
       
    25 
       
    26 #include    "MCAMessagesWriteInterface.h"
       
    27 #include    "MCAMessagesReadInterface.h"
       
    28 
       
    29 #include    "MCAMessageCreator.h"
       
    30 #include    "MCAMessageContainerInfo.h"
       
    31 
       
    32 #include    "impsbuilddefinitions.h"
       
    33 
       
    34 #include	"CCAConversationPC.h"
       
    35 #include	"CCAEngine.h"
       
    36 #include 	"MCAProcessManager.h"
       
    37 #include 	"CCAProcessManagerFactory.h"
       
    38 #include	"MCAMessage.h"
       
    39 #include	"MCAConversationMessage.h"
       
    40 #include	"CCAConversationMessage.h"
       
    41 
       
    42 #include	"MCARecordedChatsPC.h"
       
    43 #include	"CCARecordedChatsPC.h"
       
    44 #include	"MCAMessageContainer.h"
       
    45 #include	"CCAGroupPC.h"
       
    46 
       
    47 #include	"MCAMessageFlowHandlerPC.h"
       
    48 #include	"CCAMessageFlowHandlerPC.h"
       
    49 
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // IMMessageUtilsPC: SendFileL
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void IMMessageUtilsPC::SendFileL(
       
    58     MCAConversationPC& aMessageRWInterfacePC,
       
    59     const MDesCArray* aSelectedNames,
       
    60     const TBool aFileProtected,
       
    61     const TDesC& aFileName,
       
    62     const TDesC8& aContentType,
       
    63     const TDesC8& aContentData,
       
    64     const TDesC& aSender /*= KNullDesC*/,
       
    65     const TDesC& aSapId /*= KNullDesC*/,
       
    66     const TDesC& aUserId /*= KNullDesC*/,
       
    67     const MDesCArray* aRecipients /*NULL*/ )
       
    68     {
       
    69 
       
    70     CCAEngine* engine = CCAProcessManagerFactory::InstanceL()->
       
    71                         GetProcessManager()->GetEngine();
       
    72 
       
    73     MCAMessageCreator& creator =
       
    74         engine->MessageUtils().MessageCreator();
       
    75 
       
    76     CCAConversationPC& msgRWInterface =
       
    77         static_cast <CCAConversationPC&>( aMessageRWInterfacePC );
       
    78     const MCAMessageContainerInfo& msgContainerInfo =
       
    79         msgRWInterface.ReadInterfaceL().TargetId();
       
    80 
       
    81 
       
    82 
       
    83     if ( !aFileProtected )
       
    84         {
       
    85 
       
    86         CHAT_DP( D_CHAT_LIT( "Sending file %S.." ), &aFileName );
       
    87 
       
    88         MCAMessageCreator::SMessageData data =
       
    89             {
       
    90             KMessageDataVersion,
       
    91             0,
       
    92             aSapId,
       
    93             aUserId,
       
    94             aSender,
       
    95             msgContainerInfo.Target(), // Recipient
       
    96             aRecipients,
       
    97             aSelectedNames,
       
    98             aFileName,
       
    99             aContentType,
       
   100             aContentData,
       
   101             MCAMessage::EMessageSent
       
   102             };
       
   103 
       
   104         MCAMessage* message = creator.CreateMessageL( data );
       
   105 #ifdef RD_SEND_NOT_SUPPORTED_CONTENT
       
   106         if ( err != KErrNone )
       
   107             {
       
   108             message->SetProcessState( MCAMessage::EContentCorrupted );
       
   109             }
       
   110 #endif //RD_SEND_NOT_SUPPORTED_CONTENT
       
   111         // Lock write interface buffer memory handling for sending
       
   112         // file, memory check is done when message is appended to
       
   113         // read container after possible image processing.
       
   114         msgRWInterface.WriteInterfaceL().LockBufferMemoryHandling( ETrue );
       
   115         msgRWInterface.WriteInterfaceL().AppendL( message );
       
   116         // Open interface
       
   117         msgRWInterface.WriteInterfaceL().LockBufferMemoryHandling( EFalse );
       
   118         }
       
   119 #ifdef RD_SEND_NOT_SUPPORTED_CONTENT
       
   120     else
       
   121         {
       
   122 
       
   123         CHAT_DP( D_CHAT_LIT( "Sending file %S.." ), &aFileName );
       
   124 
       
   125         MCAMessageCreator::SMessageData data =
       
   126             {
       
   127             KMessageDataVersion,
       
   128             0,
       
   129             aSapId,
       
   130             aUserId,
       
   131             aSender,
       
   132             msgContainerInfo.Target(), // Recipient
       
   133             aRecipients,
       
   134             aSelectedNames,
       
   135             aFileName,
       
   136             aContentType,
       
   137             aContentData,
       
   138             MCAMessage::EMessageSent
       
   139             };
       
   140         MCAMessage* message = creator.CreateMessageL( data );
       
   141         message->SetProcessState( MCAMessage::EContentNotSupportedDrm );
       
   142         // Lock write interface buffer memory handling for sending
       
   143         // file, memory check is done when message is appended to
       
   144         // read container after possible image processing.
       
   145         msgRWInterface.WriteInterface().LockBufferMemoryHandling( ETrue );
       
   146         msgRWInterface.WriteInterface().AppendL( message );
       
   147         // Open interface
       
   148         msgRWInterface.WriteInterface().LockBufferMemoryHandling( EFalse );
       
   149         }
       
   150 #endif //RD_SEND_NOT_SUPPORTED_CONTENT        
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CCAMessageUtilsPC: SendMessageL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 
       
   161 EXPORT_C TBool IMMessageUtilsPC::SendMessageL(
       
   162     const MCAConversationMessage& aMessage,
       
   163     const TDesC& aRecipient,
       
   164     MCAConversationPC& aMessageRWInterfacePC,
       
   165     const MDesCArray* aSelectedNames,
       
   166     const TDesC& aSender /*= KNullDesC*/,
       
   167     const TDesC& aSapId /*= KNullDesC*/,
       
   168     const TDesC& aUserId /*= KNullDesC*/,
       
   169     const TDesC& aFileName /*= KNullDesC*/,
       
   170     const MDesCArray* aRecipients /*NULL*/ )
       
   171     {
       
   172 
       
   173     CCAEngine* engine =
       
   174         CCAProcessManagerFactory::InstanceL()->
       
   175         GetProcessManager()->GetEngine();
       
   176 
       
   177 
       
   178     MCAMessageCreator& creator =
       
   179         engine->MessageUtils().MessageCreator();
       
   180     CCAConversationPC& msgRWInterface =
       
   181         static_cast <CCAConversationPC&>(
       
   182             aMessageRWInterfacePC );
       
   183 
       
   184 
       
   185     MCAMessageCreator::SMessageData data =
       
   186         {
       
   187         KMessageDataVersion,
       
   188         0,
       
   189         aSapId,
       
   190         aUserId,
       
   191         aSender,
       
   192         aRecipient,
       
   193         aRecipients,
       
   194         aSelectedNames,
       
   195         aFileName,
       
   196         aMessage.MimeType(),
       
   197         aMessage.ContentData(),
       
   198         MCAMessage::EMessageSent
       
   199         };
       
   200 
       
   201     // Create and write
       
   202     MCAMessage* newMessage = creator.CreateMessageL( data );
       
   203     newMessage->SetProcessState( MCAMessage::EContentReady );
       
   204     msgRWInterface.WriteInterfaceL().AppendL( newMessage );
       
   205 
       
   206     // message handled succesfully
       
   207     return ETrue;
       
   208 
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // IMMessageUtilsPC::CloneMessageL()
       
   214 // (other items were commented in a header).
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 EXPORT_C MCAConversationMessage* IMMessageUtilsPC::CloneMessageL(
       
   218     const MCAConversationMessage& aFwdSource )
       
   219     {
       
   220 
       
   221     MCAConversationMessage& FwdMessageTmp =
       
   222         const_cast <MCAConversationMessage&>( aFwdSource );
       
   223 
       
   224 
       
   225     CCAConversationMessage* FwdMessage =
       
   226         dynamic_cast <CCAConversationMessage*>( &FwdMessageTmp );
       
   227 
       
   228     if ( !FwdMessage )
       
   229         {
       
   230         return NULL;
       
   231         }
       
   232 
       
   233     MCAProcessManager* processManager =
       
   234         CCAProcessManagerFactory::InstanceL()->GetProcessManager();
       
   235     CCAEngine&	engine ( *processManager->GetEngine() );
       
   236 
       
   237     MCAMessage* Msg =
       
   238         engine.MessageUtils().MessageCreator().CloneMessageL(
       
   239             &FwdMessage->GetMessage() );
       
   240 
       
   241     //transfer the ownership of Msg to the CCAConversationMessage
       
   242     CCAConversationMessage* NewFwdMsg = CCAConversationMessage::NewL( *Msg, Msg );
       
   243 
       
   244     return NewFwdMsg;
       
   245 
       
   246     }
       
   247 
       
   248 
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CCAMessageFlowHandlerPC::CreateInstanceL
       
   252 //
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C MCAMessageFlowHandlerPC* IMMessageUtilsPC::CreateInstanceL(
       
   256     MCAMessageContainer& aMessageContainer,
       
   257     MCAConversationPC& aConversationPC,
       
   258     TBool aRecordedChatHandler )
       
   259     {
       
   260 
       
   261     CCAConversationPC& conversationPC =
       
   262         *static_cast<CCAConversationPC*>( &aConversationPC );
       
   263 
       
   264     MCAProcessManager* processManager =
       
   265         CCAProcessManagerFactory::InstanceL()->GetProcessManager();
       
   266     CCAEngine&	engine ( *processManager->GetEngine() );
       
   267 
       
   268     CCAMessageFlowHandlerPC* FlowHandler =
       
   269         CCAMessageFlowHandlerPC::NewL(
       
   270             aMessageContainer,
       
   271             conversationPC.ReadInterfaceL(),
       
   272             *engine.GetInternalSettingsInterface(),
       
   273             aRecordedChatHandler );
       
   274 
       
   275     return 	FlowHandler;
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CCAMessageFlowHandlerPC::CreateInstanceL
       
   280 //
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C MCAMessageFlowHandlerPC* IMMessageUtilsPC::CreateInstanceL(
       
   284     MCAMessageContainer& aMessageContainer,
       
   285     MCAGroupPC& aGroupPC,
       
   286     TBool aRecordedChatHandler )
       
   287     {
       
   288 
       
   289     CCAGroupPC& groupPC =
       
   290         *static_cast<CCAGroupPC*>( &aGroupPC );
       
   291 
       
   292     MCAProcessManager* processManager =
       
   293         CCAProcessManagerFactory::InstanceL()->GetProcessManager();
       
   294     CCAEngine&	engine ( *processManager->GetEngine() );
       
   295 
       
   296     CCAMessageFlowHandlerPC* FlowHandler =
       
   297         CCAMessageFlowHandlerPC::NewL(
       
   298             aMessageContainer,
       
   299             groupPC.ReadInterfaceL(),
       
   300             *engine.GetInternalSettingsInterface(),
       
   301             aRecordedChatHandler );
       
   302 
       
   303     return 	FlowHandler;
       
   304     }
       
   305 
       
   306 
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CCAMessageFlowHandlerPC::CreateInstanceL
       
   310 //
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 EXPORT_C MCAMessageFlowHandlerPC* IMMessageUtilsPC::CreateInstanceL(
       
   314     MCAMessageContainer& aMessageContainer,
       
   315     MCARecordedChatsPC& aRecChatsPC,
       
   316     TBool aRecordedChatHandler )
       
   317     {
       
   318 
       
   319     CCARecordedChatsPC& recordedChatsPC =
       
   320         *static_cast<CCARecordedChatsPC*>( &aRecChatsPC );
       
   321 
       
   322     MCAProcessManager* processManager =
       
   323         CCAProcessManagerFactory::InstanceL()->GetProcessManager();
       
   324     CCAEngine&	engine ( *processManager->GetEngine() );
       
   325 
       
   326     CCAMessageFlowHandlerPC* FlowHandler = CCAMessageFlowHandlerPC::NewL(
       
   327                                                aMessageContainer,
       
   328                                                recordedChatsPC.ReadInterfaceL(),
       
   329                                                *engine.GetInternalSettingsInterface(),
       
   330                                                aRecordedChatHandler );
       
   331 
       
   332     return FlowHandler;
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CCAMessageUtilsPC: SendFileL
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C void IMMessageUtilsPC::SendFileL(
       
   340     MCAGroupPC& aMessageRWInterfacePC,
       
   341     const MDesCArray* aSelectedNames,
       
   342     const TBool aFileProtected,
       
   343     const TDesC& aFileName,
       
   344     const TDesC8& aContentType,
       
   345     const TDesC8& aContentData,
       
   346     const TDesC& aSender /*= KNullDesC*/,
       
   347     const TDesC& aSapId /*= KNullDesC*/,
       
   348     const TDesC& aUserId /*= KNullDesC*/,
       
   349     const MDesCArray* aRecipients /*NULL*/ )
       
   350     {
       
   351 
       
   352     CCAEngine* engine = CCAProcessManagerFactory::InstanceL()->
       
   353                         GetProcessManager()->GetEngine();
       
   354 
       
   355     MCAMessageCreator& creator =
       
   356         engine->MessageUtils().MessageCreator();
       
   357 
       
   358     CCAGroupPC& msgRWInterface =
       
   359         static_cast <CCAGroupPC&>( aMessageRWInterfacePC );
       
   360     const MCAMessageContainerInfo& msgContainerInfo =
       
   361         msgRWInterface.ReadInterfaceL().TargetId();
       
   362 
       
   363 
       
   364 
       
   365     if ( !aFileProtected )
       
   366         {
       
   367 
       
   368         CHAT_DP( D_CHAT_LIT( "Sending file %S.." ), &aFileName );
       
   369 
       
   370         MCAMessageCreator::SMessageData data =
       
   371             {
       
   372             KMessageDataVersion,
       
   373             0,
       
   374             aSapId,
       
   375             aUserId,
       
   376             aSender,
       
   377             msgContainerInfo.Target(), // Recipient
       
   378             aRecipients,
       
   379             aSelectedNames,
       
   380             aFileName,
       
   381             aContentType,
       
   382             aContentData,
       
   383             MCAMessage::EMessageSent
       
   384             };
       
   385 
       
   386         MCAMessage* message = creator.CreateMessageL( data );
       
   387 #ifdef RD_SEND_NOT_SUPPORTED_CONTENT
       
   388         if ( err != KErrNone )
       
   389             {
       
   390             message->SetProcessState( MCAMessage::EContentCorrupted );
       
   391             }
       
   392 #endif //RD_SEND_NOT_SUPPORTED_CONTENT
       
   393         // Lock write interface buffer memory handling for sending
       
   394         // file, memory check is done when message is appended to
       
   395         // read container after possible image processing.
       
   396         msgRWInterface.WriteInterfaceL().LockBufferMemoryHandling( ETrue );
       
   397         msgRWInterface.WriteInterfaceL().AppendL( message );
       
   398         // Open interface
       
   399         msgRWInterface.WriteInterfaceL().LockBufferMemoryHandling( EFalse );
       
   400         }
       
   401 #ifdef RD_SEND_NOT_SUPPORTED_CONTENT
       
   402     else
       
   403         {
       
   404 
       
   405         CHAT_DP( D_CHAT_LIT( "Sending file %S.." ), &aFileName );
       
   406 
       
   407         MCAMessageCreator::SMessageData data =
       
   408             {
       
   409             KMessageDataVersion,
       
   410             0,
       
   411             aSapId,
       
   412             aUserId,
       
   413             aSender,
       
   414             msgContainerInfo.Target(), // Recipient
       
   415             aRecipients,
       
   416             aSelectedNames,
       
   417             aFileName,
       
   418             aContentType,
       
   419             aContentData,
       
   420             MCAMessage::EMessageSent
       
   421             };
       
   422         MCAMessage* message = creator.CreateMessageL( data );
       
   423         message->SetProcessState(
       
   424             MCAMessage::EContentNotSupportedDrm );
       
   425         // Lock write interface buffer memory handling for sending
       
   426         // file, memory check is done when message is appended to
       
   427         // read container after possible image processing.
       
   428         msgRWInterface.WriteInterface().LockBufferMemoryHandling(
       
   429             ETrue );
       
   430         msgRWInterface.WriteInterface().AppendL( message );
       
   431         // Open interface
       
   432         msgRWInterface.WriteInterface().LockBufferMemoryHandling(
       
   433             EFalse );
       
   434         }
       
   435 #endif //RD_SEND_NOT_SUPPORTED_CONTENT        
       
   436     }
       
   437 
       
   438 
       
   439 
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CCAMessageUtilsPC: SendMessageL
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 
       
   446 EXPORT_C TBool IMMessageUtilsPC::SendMessageL(
       
   447     const MCAConversationMessage& aMessage,
       
   448     const TDesC& aRecipient,
       
   449     MCAGroupPC& aMessageRWInterfacePC,
       
   450     const MDesCArray* aSelectedNames,
       
   451     const TDesC& aSender /*= KNullDesC*/,
       
   452     const TDesC& aSapId /*= KNullDesC*/,
       
   453     const TDesC& aUserId /*= KNullDesC*/,
       
   454     const TDesC& aFileName /*= KNullDesC*/,
       
   455     const MDesCArray* aRecipients /*NULL*/ )
       
   456     {
       
   457 
       
   458     CCAEngine* engine = CCAProcessManagerFactory::InstanceL()->
       
   459                         GetProcessManager()->GetEngine();
       
   460 
       
   461 
       
   462     MCAMessageCreator& creator =
       
   463         engine->MessageUtils().MessageCreator();
       
   464     CCAGroupPC& msgRWInterface =
       
   465         static_cast <CCAGroupPC&>( aMessageRWInterfacePC );
       
   466 
       
   467 
       
   468     MCAMessageCreator::SMessageData data =
       
   469         {
       
   470         KMessageDataVersion,
       
   471         0,
       
   472         aSapId,
       
   473         aUserId,
       
   474         aSender,
       
   475         aRecipient,
       
   476         aRecipients,
       
   477         aSelectedNames,
       
   478         aFileName,
       
   479         aMessage.MimeType(),
       
   480         aMessage.ContentData(),
       
   481         MCAMessage::EMessageSent
       
   482         };
       
   483 
       
   484     // Create and write
       
   485     MCAMessage* newMessage = creator.CreateMessageL( data );
       
   486     newMessage->SetProcessState( MCAMessage::EContentReady );
       
   487     msgRWInterface.WriteInterfaceL().AppendL( newMessage );
       
   488 
       
   489     // message handled succesfully
       
   490     return ETrue;
       
   491 
       
   492     }
       
   493 
       
   494 
       
   495 //  End of File