javaextensions/wma/mms/src.s60/cmmsmessageinformation.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  ?Description
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "logger.h"
       
    21 #include "s60commonutils.h"
       
    22 #include "cmmsmessageinformation.h"
       
    23 
       
    24 using namespace java::util;
       
    25 
       
    26 namespace java
       
    27 {
       
    28 namespace wma
       
    29 {
       
    30 const TInt KArrayGranularity = 2;
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 //------------------------------------------------------------------------------
       
    34 
       
    35 /*******************************************************************************
       
    36  ***************************   CMidMessageInformation  *************************
       
    37  ******************************************************************************/
       
    38 /*------------------------------------------------------------------------------
       
    39  *    CMidMessageInformation
       
    40  *
       
    41  *------------------------------------------------------------------------------
       
    42  */
       
    43 CMMSMessageInformation::CMMSMessageInformation()
       
    44 {
       
    45     JELOG2(EWMA);
       
    46 }
       
    47 
       
    48 /*------------------------------------------------------------------------------
       
    49  *  NewL
       
    50  *
       
    51  *------------------------------------------------------------------------------
       
    52  */
       
    53 CMMSMessageInformation* CMMSMessageInformation::NewL(const TDesC& aFromAddress,
       
    54         TInt64 aDate, const TDesC8& aApplicationID8, TMsvId aReceivedMsvId)
       
    55 {
       
    56     JELOG2(EWMA);
       
    57     CMMSMessageInformation *self = new(ELeave) CMMSMessageInformation;
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL(aFromAddress, aDate, aApplicationID8, aReceivedMsvId);
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62 }
       
    63 /*------------------------------------------------------------------------------
       
    64  *    ConstructL
       
    65  *
       
    66  *------------------------------------------------------------------------------
       
    67  */
       
    68 void CMMSMessageInformation::ConstructL(const TDesC& aFromAddress,TInt64 aDate,
       
    69                                         const TDesC8& aApplicationID8,
       
    70                                         TMsvId aReceivedMsvId)
       
    71 {
       
    72     JELOG2(EWMA);
       
    73     S60CommonUtils::ConvertWiderToNarrowL(aFromAddress, (TDesC8*&)mFromAddress8);
       
    74     S60CommonUtils::CopyNarrowL(aApplicationID8, (TDesC8*&) mApplicationID8);
       
    75     mDateTime = aDate;
       
    76     mMessagePriority = EMmsPriorityHigh;
       
    77     mReceivedMsvId = aReceivedMsvId;
       
    78     mAttachmentArray
       
    79     = new(ELeave) CArrayPtrSeg<CMMSMessageAttachment> (KArrayGranularity);
       
    80     mToAddressArray = new(ELeave) CArrayPtrSeg<TDesC> (KArrayGranularity);
       
    81     mCcAddressArray = new(ELeave) CArrayPtrSeg<TDesC> (1);
       
    82     mBccAddressArray = new(ELeave) CArrayPtrSeg<TDesC> (1);
       
    83 }
       
    84 /*------------------------------------------------------------------------------
       
    85  *    ~CMidMessageInformation
       
    86  * This will delete the following
       
    87  * iFromAddress8;    // HBufC*
       
    88  * iApplicationID8;  // HBufC*
       
    89  * iReplyToApplicationID8;
       
    90  * iMessageSubject8;  //HBufC*
       
    91  * iToAddressArray   Arrays just not their contents
       
    92  * iBccAddressArray  Arrays just not their contents
       
    93  * iCcAddressArray   Arrays just not their contents
       
    94  *------------------------------------------------------------------------------
       
    95  */
       
    96 CMMSMessageInformation::~CMMSMessageInformation()
       
    97 {
       
    98     JELOG2(EWMA);
       
    99     delete mFromAddress8;
       
   100     mFromAddress8 = NULL; // HBufC*
       
   101     delete mApplicationID8;
       
   102     mApplicationID8 = NULL; // HBufC*
       
   103     delete mReplyToApplicationID8;
       
   104     mReplyToApplicationID8 = NULL;
       
   105     delete mMessageSubject8;
       
   106     mMessageSubject8 = NULL; //HBufC*
       
   107     //
       
   108     mDateTime = 0;
       
   109     mMessageSize = 0;
       
   110 
       
   111     if (mAttachmentArray)
       
   112     {
       
   113         mAttachmentArray->ResetAndDestroy();
       
   114         delete mAttachmentArray;
       
   115         mAttachmentArray = NULL;
       
   116     }
       
   117 
       
   118     if (mToAddressArray)
       
   119     {
       
   120         mToAddressArray->ResetAndDestroy();
       
   121         delete mToAddressArray;
       
   122         mToAddressArray = NULL;
       
   123     }
       
   124     if (mBccAddressArray)
       
   125     {
       
   126         mBccAddressArray->ResetAndDestroy();
       
   127         delete mBccAddressArray;
       
   128         mBccAddressArray = NULL;
       
   129     }
       
   130     if (mCcAddressArray)
       
   131     {
       
   132         mCcAddressArray->ResetAndDestroy();
       
   133         delete mCcAddressArray;
       
   134         mCcAddressArray = NULL;
       
   135     }
       
   136 }
       
   137 /*------------------------------------------------------------------------------
       
   138  * Attachment
       
   139  * return null if there is not more attachement
       
   140  *------------------------------------------------------------------------------
       
   141  */
       
   142 CMMSMessageAttachment& CMMSMessageInformation::Attachment(TInt aIndex)
       
   143 {
       
   144     JELOG2(EWMA);
       
   145     CMMSMessageAttachment* attachment = NULL;
       
   146     if (aIndex >= 0 && aIndex < mAttachmentArray->Count())
       
   147         attachment = mAttachmentArray->At(aIndex);
       
   148     return *attachment;
       
   149 }
       
   150 /*------------------------------------------------------------------------------
       
   151  * InsertAttachmentL
       
   152  * Insert Attachment, Attachment will be applended in the array
       
   153  *------------------------------------------------------------------------------
       
   154  */
       
   155 void CMMSMessageInformation::InsertAttachmentL(
       
   156     CMMSMessageAttachment* aMessageAttachment)
       
   157 {
       
   158     JELOG2(EWMA);
       
   159     mAttachmentArray->AppendL(aMessageAttachment);
       
   160 }
       
   161 /*------------------------------------------------------------------------------
       
   162  * SetMessageSubjectL
       
   163  * set the subject of the message
       
   164  *------------------------------------------------------------------------------
       
   165  */
       
   166 void CMMSMessageInformation::SetMessageSubjectL(TDesC16& aSubject)
       
   167 {
       
   168     JELOG2(EWMA);
       
   169     delete mMessageSubject8;
       
   170     mMessageSubject8 = NULL;
       
   171     S60CommonUtils::ConvertWiderToNarrowL(aSubject, (TDesC8*&) mMessageSubject8);
       
   172 }
       
   173 /*------------------------------------------------------------------------------
       
   174  * SetMessageSubjectL
       
   175  * set the subject of the message
       
   176  *------------------------------------------------------------------------------
       
   177  */
       
   178 void CMMSMessageInformation::SetMessageSubjectL(TDesC8& aSubject)
       
   179 {
       
   180     JELOG2(EWMA);
       
   181     delete mMessageSubject8;
       
   182     mMessageSubject8 = NULL;
       
   183     S60CommonUtils::CopyNarrowL(aSubject, (TDesC8*&) mMessageSubject8);
       
   184 }
       
   185 /*------------------------------------------------------------------------------
       
   186  * MessageFromAddress
       
   187  *  Get from Message Address
       
   188  *------------------------------------------------------------------------------
       
   189  */
       
   190 TDesC8& CMMSMessageInformation::MessageFromAddressL()
       
   191 {
       
   192     JELOG2(EWMA);
       
   193     return *mFromAddress8;
       
   194 }
       
   195 /*------------------------------------------------------------------------------
       
   196  * SetApplicationIdL(const TDesC8& aAppId)
       
   197  *------------------------------------------------------------------------------
       
   198  */
       
   199 void CMMSMessageInformation::SetApplicationIdL(const TDesC8& aAppId)
       
   200 {
       
   201     JELOG2(EWMA);
       
   202     delete mApplicationID8;
       
   203     mApplicationID8 = NULL;
       
   204     S60CommonUtils::CopyNarrowL(aAppId, (TDesC8*&) mApplicationID8);
       
   205 }
       
   206 /*------------------------------------------------------------------------------
       
   207  * SetApplicationIdL(const TDesC16& aAppId)
       
   208  *
       
   209  *------------------------------------------------------------------------------
       
   210  */
       
   211 void CMMSMessageInformation::SetApplicationIdL(const TDesC16& aAppId)
       
   212 {
       
   213     JELOG2(EWMA);
       
   214     delete mApplicationID8;
       
   215     mApplicationID8 = NULL;
       
   216     S60CommonUtils::ConvertWiderToNarrowL(aAppId, (TDesC8*&) mApplicationID8);
       
   217 }
       
   218 /*------------------------------------------------------------------------------
       
   219  *  TDesC8& ApplicationID
       
   220  *  GetApplicationID
       
   221  *
       
   222  *------------------------------------------------------------------------------
       
   223  */
       
   224 TDesC8& CMMSMessageInformation::ApplicationIdL()
       
   225 {
       
   226     JELOG2(EWMA);
       
   227     return *mApplicationID8;
       
   228 }
       
   229 /*------------------------------------------------------------------------------
       
   230  * SetReplyToApplicationIdL(const TDesC16& aReplyAppId)
       
   231  * Set reply AppId
       
   232  *------------------------------------------------------------------------------
       
   233  */
       
   234 void CMMSMessageInformation::SetReplyToApplicationIdL(
       
   235     const TDesC16& aReplyAppId)
       
   236 {
       
   237     JELOG2(EWMA);
       
   238     delete mReplyToApplicationID8;
       
   239     mReplyToApplicationID8 = NULL;
       
   240     S60CommonUtils::ConvertWiderToNarrowL(aReplyAppId,
       
   241                                           (TDesC8*&) mReplyToApplicationID8);
       
   242 }
       
   243 /*------------------------------------------------------------------------------
       
   244  * SetApplicationIdL(const TDesC8& aAppId)
       
   245  *------------------------------------------------------------------------------
       
   246  */
       
   247 void CMMSMessageInformation::SetReplyToApplicationIdL(
       
   248     const TDesC8& aReplyToAppId)
       
   249 {
       
   250     JELOG2(EWMA);
       
   251     delete mReplyToApplicationID8;
       
   252     mReplyToApplicationID8 = NULL;
       
   253     S60CommonUtils::CopyNarrowL(aReplyToAppId, (TDesC8*&)mReplyToApplicationID8);
       
   254 }
       
   255 /*------------------------------------------------------------------------------
       
   256  * TDesC8& ReplyToApplicationIdL
       
   257  *------------------------------------------------------------------------------
       
   258  */
       
   259 TDesC8& CMMSMessageInformation::ReplyToApplicationIdL()
       
   260 {
       
   261     JELOG2(EWMA);
       
   262     return *mReplyToApplicationID8;
       
   263 }
       
   264 /*------------------------------------------------------------------------------
       
   265  * TDesC8& MessageSubject
       
   266  * Get the message subject
       
   267  *------------------------------------------------------------------------------
       
   268  */
       
   269 TDesC8& CMMSMessageInformation::MessageSubjectL() const
       
   270 {
       
   271     JELOG2(EWMA);
       
   272     return *mMessageSubject8;
       
   273 }
       
   274 /*------------------------------------------------------------------------------
       
   275  * TInt SetMessageSize
       
   276  * Set the message size
       
   277  *------------------------------------------------------------------------------
       
   278  */
       
   279 void CMMSMessageInformation::SetMessageSize(TInt aSize)
       
   280 {
       
   281     JELOG2(EWMA);
       
   282     mMessageSize = aSize;
       
   283 }
       
   284 /*------------------------------------------------------------------------------
       
   285  * TInt AddressesCount
       
   286  *------------------------------------------------------------------------------
       
   287  */
       
   288 TInt CMMSMessageInformation::AddressesCount(
       
   289     TMsvRecipientTypeValues aAddressType)
       
   290 {
       
   291     JELOG2(EWMA);
       
   292     TInt count = 0;
       
   293     switch (aAddressType)
       
   294     {
       
   295     case EMsvRecipientTo:
       
   296     {
       
   297         count = mToAddressArray->Count();
       
   298         break;
       
   299     }
       
   300     case EMsvRecipientCc:
       
   301     {
       
   302         count = mCcAddressArray->Count();
       
   303         break;
       
   304     }
       
   305     case EMsvRecipientBcc:
       
   306     {
       
   307         count = mBccAddressArray->Count();
       
   308         break;
       
   309     }
       
   310     default:
       
   311         break;
       
   312     }
       
   313     return count;
       
   314 }
       
   315 /*------------------------------------------------------------------------------
       
   316  * TDesC& MessageAddress
       
   317  * return type is TDesC
       
   318  *------------------------------------------------------------------------------
       
   319  */
       
   320 TDesC& CMMSMessageInformation::MessageAddressL(
       
   321     TMsvRecipientTypeValues aAddressType, TInt aIndex)
       
   322 {
       
   323     JELOG2(EWMA);
       
   324     TDesC* address = NULL;
       
   325 
       
   326     if (aIndex < 0) // aIndex is less then zero return null;
       
   327         return *address;
       
   328 
       
   329     switch (aAddressType)
       
   330     {
       
   331     case EMsvRecipientTo:
       
   332     {
       
   333         if (aIndex < mToAddressArray->Count())
       
   334             address = mToAddressArray->At(aIndex);
       
   335         break;
       
   336     }
       
   337     case EMsvRecipientCc:
       
   338     {
       
   339         if (aIndex < mCcAddressArray->Count())
       
   340             address = mCcAddressArray->At(aIndex);
       
   341         break;
       
   342     }
       
   343     case EMsvRecipientBcc:
       
   344     {
       
   345         if (aIndex < mBccAddressArray->Count())
       
   346             address = mBccAddressArray->At(aIndex);
       
   347         break;
       
   348     }
       
   349     default:
       
   350         break;
       
   351     }
       
   352     return *address;
       
   353 }
       
   354 
       
   355 /*------------------------------------------------------------------------------
       
   356  * AddAddressL(TMsvRecipientTypeValues aAddressType, TDesC8& aAddress8)
       
   357  *------------------------------------------------------------------------------
       
   358  */
       
   359 void CMMSMessageInformation::AddAddressL(TMsvRecipientTypeValues aAddressType,
       
   360         TDesC8& aAddress8)
       
   361 {
       
   362     JELOG2(EWMA);
       
   363     TDesC16* address = NULL;
       
   364     S60CommonUtils::ConvertNarrowToWiderLC(aAddress8, address);
       
   365     AddAddressL(aAddressType, address);
       
   366     CleanupStack::Pop(address);
       
   367 }
       
   368 
       
   369 /*------------------------------------------------------------------------------
       
   370  * AddAddressL(TMsvRecipientTypeValues aAddressType, TDesC16& aAddress)
       
   371  *------------------------------------------------------------------------------
       
   372  */
       
   373 void CMMSMessageInformation::AddAddressL(TMsvRecipientTypeValues aAddressType,
       
   374         TDesC16* aAddress)
       
   375 {
       
   376     JELOG2(EWMA);
       
   377     if (!aAddress)
       
   378         return;
       
   379 
       
   380     switch (aAddressType)
       
   381     {
       
   382     case EMsvRecipientTo:
       
   383     {
       
   384         AddToAddressL(aAddress);
       
   385         break;
       
   386     }
       
   387     case EMsvRecipientCc:
       
   388     {
       
   389         AddCcAddressL(aAddress);
       
   390         break;
       
   391     }
       
   392     case EMsvRecipientBcc:
       
   393     {
       
   394         AddBccAddressL(aAddress);
       
   395         break;
       
   396     }
       
   397     default:
       
   398         break;
       
   399     }
       
   400 }
       
   401 /*------------------------------------------------------------------------------
       
   402  * AddToAddressL
       
   403  *------------------------------------------------------------------------------
       
   404  */
       
   405 void CMMSMessageInformation::AddToAddressL(TDesC* aAddress)
       
   406 {
       
   407     JELOG2(EWMA);
       
   408     if (aAddress)
       
   409         mToAddressArray->AppendL(aAddress);
       
   410 }
       
   411 /*------------------------------------------------------------------------------
       
   412  * AddCcAddressL
       
   413  *------------------------------------------------------------------------------
       
   414  */
       
   415 void CMMSMessageInformation::AddCcAddressL(TDesC* aAddress)
       
   416 {
       
   417     JELOG2(EWMA);
       
   418     if (aAddress)
       
   419         mCcAddressArray->AppendL(aAddress);
       
   420 }
       
   421 /*------------------------------------------------------------------------------
       
   422  *
       
   423  *------------------------------------------------------------------------------
       
   424  */
       
   425 void CMMSMessageInformation::AddBccAddressL(TDesC* aAddress)
       
   426 {
       
   427     JELOG2(EWMA);
       
   428     if (aAddress)
       
   429         mBccAddressArray->AppendL(aAddress);
       
   430 }
       
   431 /*------------------------------------------------------------------------------
       
   432  * SetMessagePriority
       
   433  *
       
   434  *------------------------------------------------------------------------------
       
   435  */
       
   436 void CMMSMessageInformation::SetMessagePriority(TMmsMessagePriority aPriority)
       
   437 {
       
   438     JELOG2(EWMA);
       
   439     mMessagePriority = aPriority;
       
   440 }
       
   441 
       
   442 // End of File
       
   443 } //namespace wma
       
   444 } //namespace java
       
   445