mmsengine/mmsmessage/src/mmsmmboxmessageheaders.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004 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:   MMBox related headers present in message PDUs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    <msvstore.h>
       
    23 #include    <badesca.h>
       
    24 
       
    25 #include    "mmsmmboxmessageheaders.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KMmsContentLocationNumber = 3;
       
    33 
       
    34 // MACROS
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 
       
    44 // ============================= LOCAL FUNCTIONS ===============================
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CMmsMMBoxMessageHeaders::CMmsMMBoxMessageHeaders
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMmsMMBoxMessageHeaders::CMmsMMBoxMessageHeaders()
       
    55     {
       
    56     // Everything is initialized to 0 by CBase
       
    57     }
       
    58 
       
    59 // Symbian OS default constructor can leave.
       
    60 void CMmsMMBoxMessageHeaders::ConstructL()
       
    61     {
       
    62     iContentLocationArray = new ( ELeave )CDesC8ArrayFlat( KMmsContentLocationNumber );
       
    63     }
       
    64     
       
    65 // Two-phased constructor.
       
    66 CMmsMMBoxMessageHeaders* CMmsMMBoxMessageHeaders::NewL()
       
    67     {
       
    68     CMmsMMBoxMessageHeaders* self = new ( ELeave ) CMmsMMBoxMessageHeaders;
       
    69     
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73 
       
    74     return self;
       
    75     }
       
    76 
       
    77 // Destructor
       
    78 CMmsMMBoxMessageHeaders::~CMmsMMBoxMessageHeaders()
       
    79     {
       
    80     delete iContentLocationArray;
       
    81     delete iMmsStoreStatusText;
       
    82     iKeywordArray.ResetAndDestroy();
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CMmsMMBoxMessageHeaders::Reset
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CMmsMMBoxMessageHeaders::Reset()
       
    90     {
       
    91     iContentLocationArray->Reset();
       
    92     delete iMmsStoreStatusText;
       
    93     iMmsStoreStatusText = NULL;
       
    94     iKeywordArray.ResetAndDestroy();
       
    95     iMmsStore = 0;
       
    96     iMmsMMState = 0;
       
    97     iMmsStored = 0;
       
    98     iMmsStoreStatus = 0;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMmsMMBoxMessageHeaders::Internalize
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CMmsMMBoxMessageHeaders::InternalizeL( RMsvReadStream& aStream )
       
   106     {
       
   107     Reset();
       
   108     iMmsStore = aStream.ReadInt32L();
       
   109     iMmsMMState = aStream.ReadInt32L();
       
   110     iMmsStored = aStream.ReadInt32L();
       
   111     iMmsStoreStatus = aStream.ReadInt32L();
       
   112 
       
   113     TInt32 length = 0;
       
   114     length = aStream.ReadInt32L();
       
   115     if ( length > 0 )
       
   116         {
       
   117         iMmsStoreStatusText = HBufC::NewL( aStream, length );
       
   118         }
       
   119 
       
   120     TInt i;
       
   121     // Read content location array if present
       
   122     length = aStream.ReadInt32L();
       
   123     TInt stringLength = 0;
       
   124     for ( i = 0; i < length; i++ )
       
   125         {
       
   126         stringLength = aStream.ReadInt32L();
       
   127         HBufC8* buf=HBufC8::NewLC( aStream, stringLength );
       
   128         iContentLocationArray->AppendL( buf->Des() );
       
   129         CleanupStack::PopAndDestroy( buf );
       
   130         }
       
   131 
       
   132     // Read Keyword array only if present
       
   133     length = aStream.ReadInt32L();
       
   134     for ( i = 0; i < length; i++ )
       
   135         {
       
   136         CMmsMMBoxFlags* item = new( ELeave )CMmsMMBoxFlags;
       
   137         CleanupStack::PushL( item );
       
   138         item->InternalizeL( aStream );
       
   139         User::LeaveIfError( iKeywordArray.Append( item ) ); 
       
   140         CleanupStack::Pop( item ); // item is in member array now
       
   141         }
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMmsMMBoxMessageHeaders::ExternalizeL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CMmsMMBoxMessageHeaders::ExternalizeL( RMsvWriteStream& aStream ) const
       
   149     {
       
   150     aStream.WriteInt32L( iMmsStore );
       
   151     aStream.WriteInt32L( iMmsMMState );
       
   152     aStream.WriteInt32L( iMmsStored );
       
   153     aStream.WriteInt32L( iMmsStoreStatus );
       
   154 
       
   155     TInt32 length = MmsStoreStatusText().Length();
       
   156     aStream.WriteInt32L( length );
       
   157     if ( length > 0 )
       
   158         {
       
   159         aStream << MmsStoreStatusText();
       
   160         }
       
   161 
       
   162     // Write the content location array
       
   163     TInt i;
       
   164     TInt count = iContentLocationArray->Count();
       
   165     aStream.WriteInt32L( count );
       
   166     for ( i = 0; i < count; i++ )
       
   167         {
       
   168         length = iContentLocationArray->MdcaPoint(i).Length();
       
   169         aStream.WriteInt32L( length );
       
   170         aStream << iContentLocationArray->MdcaPoint(i);
       
   171         }
       
   172 
       
   173     // Write Keyword array only if present
       
   174     length = iKeywordArray.Count();
       
   175     aStream.WriteInt32L( length );
       
   176     for ( i = 0; i < length; i++ )
       
   177         {
       
   178         iKeywordArray[i]->ExternalizeL( aStream );
       
   179         }
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CMmsMMBoxMessageHeaders::Size
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 TInt CMmsMMBoxMessageHeaders::Size() const
       
   187     {
       
   188     TInt size = 0;
       
   189     size += sizeof( iMmsStore );
       
   190     size += sizeof( iMmsMMState );
       
   191     size += sizeof( iMmsStored );
       
   192     size += sizeof( iMmsStoreStatus );
       
   193     size += sizeof( TInt32 );
       
   194     size += MmsStoreStatusText().Size(); // size, not length to get number of bytes
       
   195     size += sizeof( TInt32 );
       
   196     TInt i;
       
   197 
       
   198     for ( i = 0; i < iContentLocationArray->Count(); i++ )
       
   199         {
       
   200         size += iContentLocationArray->MdcaPoint(i).Size();
       
   201         }
       
   202 
       
   203     size += sizeof( TInt32 );
       
   204     for ( i = 0; i < iKeywordArray.Count(); i++)
       
   205         {
       
   206         size += iKeywordArray[i]->Size();
       
   207         }
       
   208 
       
   209     return size;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CMmsMMBoxMessageHeaders::MmsStoreStatusText
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 EXPORT_C TPtrC CMmsMMBoxMessageHeaders::MmsStoreStatusText() const
       
   217     {
       
   218     return iMmsStoreStatusText ? TPtrC( *iMmsStoreStatusText ) : TPtrC(); 
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CMmsMMBoxMessageHeaders::SetMmsStoreStatusTextL
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 EXPORT_C void CMmsMMBoxMessageHeaders::SetMmsStoreStatusTextL( const TDesC& aText )
       
   226     {
       
   227     // If the length of the new text is 0, the text is cleared
       
   228     delete iMmsStoreStatusText;
       
   229     iMmsStoreStatusText = NULL;
       
   230     if ( aText.Length() > 0 )
       
   231         {
       
   232         iMmsStoreStatusText = aText.AllocL();
       
   233         }
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CMmsMMBoxMessageHeaders::AppendKeywordItemL
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C void CMmsMMBoxMessageHeaders::AppendKeywordItemL( TInt aToken, const TDesC& aKeyword )
       
   241     {
       
   242     TInt index = FindItemWithKeyword( aKeyword );
       
   243     if ( index == KErrNotFound )
       
   244         {
       
   245         CMmsMMBoxFlags* item = new( ELeave ) CMmsMMBoxFlags;
       
   246         CleanupStack::PushL( item );
       
   247         item->SetToken( aToken );
       
   248         item->SetKeywordL( aKeyword );
       
   249         TInt error = iKeywordArray.Append( item );
       
   250         User::LeaveIfError( error ); // should only leave if out of memory
       
   251         CleanupStack::Pop( item ); // Item is now in array
       
   252         }
       
   253     else
       
   254         {
       
   255         // index is valid as it is what we just found
       
   256         iKeywordArray[index]->SetToken( aToken );
       
   257         }
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CMmsMMBoxMessageHeaders::DeleteKeywordItem
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 EXPORT_C void CMmsMMBoxMessageHeaders::DeleteKeywordItem( const TDesC& aKeyword )
       
   265     {
       
   266     TInt index = FindItemWithKeyword( aKeyword );
       
   267     if ( index != KErrNotFound )
       
   268         {
       
   269         CMmsMMBoxFlags* deadItem = iKeywordArray[index];
       
   270         iKeywordArray.Remove( index );
       
   271         delete deadItem;
       
   272         }
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CMmsMMBoxMessageHeaders::FindItemWithKeyword
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 EXPORT_C TInt CMmsMMBoxMessageHeaders::FindItemWithKeyword( const TDesC& aKeyword )
       
   280     {
       
   281     TInt i;
       
   282     TInt index = KErrNotFound;
       
   283     for ( i = 0; i < iKeywordArray.Count() && index == KErrNotFound; i++ )
       
   284         {
       
   285         if ( iKeywordArray[i]->Keyword().CompareF( aKeyword ) == 0 )
       
   286             {
       
   287             index = i;
       
   288             }
       
   289         }
       
   290     return index;
       
   291     }
       
   292 
       
   293 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   294 
       
   295 //  End of File