codhandler/codeng/src/DownloadDataClient.cpp
changeset 0 dd21522fd290
child 10 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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: 
       
    15 *      Implementation of class CDownloadDataClient.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <s32mem.h>
       
    24 #include "DownloadDataClient.h"
       
    25 #include "CodData.h"
       
    26 #include "CodUtil.h"
       
    27 
       
    28 // ================= CONSTANTS =======================
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33     
       
    34 // ---------------------------------------------------------
       
    35 // CMediaDataClient::NewL()
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 CMediaDataClient* CMediaDataClient::NewL()
       
    39     {
       
    40     CMediaDataClient* data = new (ELeave) CMediaDataClient();
       
    41     CleanupStack::PushL( data );
       
    42     data->ConstructL();
       
    43     CleanupStack::Pop(); //data
       
    44     return data;
       
    45     }
       
    46     
       
    47 // ---------------------------------------------------------
       
    48 // CMediaDataClient::NewLC()
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CMediaDataClient* CMediaDataClient::NewLC()
       
    52     {
       
    53     CMediaDataClient* data = new (ELeave) CMediaDataClient();
       
    54     CleanupStack::PushL( data );
       
    55     data->ConstructL();
       
    56     return data;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CMediaDataClient::~CMediaDataClient()
       
    61 // ---------------------------------------------------------
       
    62 //    
       
    63 CMediaDataClient::~CMediaDataClient()
       
    64     {
       
    65     delete iName;
       
    66     delete iUrl;
       
    67     delete iIcon;
       
    68     delete iSourceUri;
       
    69     delete iRedirUrl;
       
    70     delete iDestFilename;
       
    71     delete iTempFilename;
       
    72     }
       
    73     
       
    74 // ---------------------------------------------------------
       
    75 // CMediaDataClient::ConstructL()
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 void CMediaDataClient::ConstructL()
       
    79     {
       
    80     iName = HBufC::NewL( 0 );
       
    81     iUrl = HBufC8::NewL( 0 );
       
    82     iTypes = new (ELeave) CDesC8ArrayFlat( KTypeGranularity );
       
    83     iIcon = HBufC8::NewL( 0 );
       
    84     iSourceUri = HBufC8::NewL( 0 );
       
    85     iRedirUrl = HBufC8::NewL( 0 );
       
    86     iDestFilename = HBufC::NewL( 0 );
       
    87     iTempFilename = HBufC::NewL( 0 );
       
    88     }
       
    89     
       
    90 // ---------------------------------------------------------
       
    91 // CMediaDataClient::Bytes()
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 TInt CMediaDataClient::Bytes() const
       
    95     {
       
    96     TInt bytes = 0;
       
    97     
       
    98     bytes += iName->Size();
       
    99     bytes += iUrl->Size();
       
   100     bytes += sizeof(iSize);
       
   101     bytes += iIcon->Size();
       
   102     bytes += iSourceUri->Size();
       
   103     bytes += sizeof(iProgressiveDl);
       
   104     bytes += sizeof(iState);
       
   105     
       
   106     bytes += iRedirUrl->Size();
       
   107     bytes += sizeof(iMethod);
       
   108     bytes += sizeof(iRedirected);
       
   109     bytes += iDestFilename->Size();
       
   110     bytes += sizeof(iDownloadedSize);
       
   111     bytes += sizeof(iDesRemovable);
       
   112     bytes += sizeof(iLastErrorId);
       
   113     bytes += sizeof(iGlobalErrorId);
       
   114     bytes += sizeof(iPausable);
       
   115     bytes += iTempFilename->Size();
       
   116     
       
   117     // iTypes array elements
       
   118     for (TInt index = 0; index < iTypes->MdcaCount(); ++index)
       
   119         bytes += iTypes->MdcaPoint(index).Size();
       
   120     
       
   121     return bytes;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CMediaDataClient::SetNameL()
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 TBool CMediaDataClient::SetNameL( const TDesC& aName )
       
   129     {
       
   130     return SetStringAttrL( iName, aName, COD_NAME_MAX_LEN );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CMediaDataClient::SetUrlL()
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 TBool CMediaDataClient::SetUrlL( const TDesC8& aUrl )
       
   138     {
       
   139     return SetStringAttrL( iUrl, aUrl, COD_URL_MAX_LEN );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CMediaDataClient::SetSize()
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 TBool CMediaDataClient::SetSize( TUint aSize )
       
   147     {
       
   148     if( aSize <= 0 )
       
   149         {
       
   150         return EFalse;
       
   151         }
       
   152     iSize = aSize;
       
   153     return ETrue;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CMediaDataClient::SetTypeL()
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 TBool CMediaDataClient::SetTypeL( const TDesC8& aType )
       
   161     {
       
   162     // Backwards-compatible deprecated method.
       
   163     iTypes->Reset();    // Replace all, support only one type.
       
   164     return AddTypeL( aType );
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CMediaDataClient::AddTypeL()
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 TBool CMediaDataClient::AddTypeL( const TDesC8& aType )
       
   172     {
       
   173     if ( aType.Length() > COD_TYPE_MAX_LEN || !aType.Length() )
       
   174         {
       
   175         return EFalse;
       
   176         }
       
   177     HBufC8* type8 = aType.AllocLC();
       
   178     iTypes->AppendL( *type8 );
       
   179     CleanupStack::PopAndDestroy(); //type8
       
   180     return ETrue;
       
   181     }
       
   182     
       
   183 // ---------------------------------------------------------
       
   184 // CMediaDataClient::ResetTypes()
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CMediaDataClient::ResetTypes()
       
   188 	{
       
   189 	iTypes->Reset();
       
   190 	}
       
   191 
       
   192 // ---------------------------------------------------------
       
   193 // CMediaDataClient::SetIconL()
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 TBool CMediaDataClient::SetIconL( const TDesC8& aIcon )
       
   197     {
       
   198     return SetStringAttrL( iIcon, aIcon, COD_ICON_MAX_LEN );
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CMediaDataClient::SetSourceUriL()
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 void CMediaDataClient::SetSourceUriL( const TDesC8& aSourceUri )
       
   206     {
       
   207     HBufC8* buf = aSourceUri.AllocL();
       
   208     delete iSourceUri;
       
   209     iSourceUri = buf;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CMediaDataClient::SetProgressiveDownload()
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CMediaDataClient::SetProgressiveDownload( TBool aProgressiveDl )
       
   217     {
       
   218     iProgressiveDl = aProgressiveDl;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CMediaDataClient::SetState()
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CMediaDataClient::SetState( TMediaObjectState aState )
       
   226     {
       
   227     iState = aState;
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // CMediaDataClient::SetResult()
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 void CMediaDataClient::SetResult( TInt aResult )
       
   235     {
       
   236     iResult = aResult;
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------
       
   240 // CMediaDataClient::SetRedirUrlL()
       
   241 // ---------------------------------------------------------
       
   242 //
       
   243 TBool CMediaDataClient::SetRedirUrlL( const TDesC8& aRedirUrl )
       
   244 	{
       
   245 	return SetStringAttrL( iRedirUrl, aRedirUrl, COD_URL_MAX_LEN );
       
   246 	}
       
   247 
       
   248 // ---------------------------------------------------------
       
   249 // CMediaDataClient::SetMethod()
       
   250 // ---------------------------------------------------------
       
   251 //
       
   252 void CMediaDataClient::SetMethod( TInt aMethod )
       
   253 	{
       
   254 	iMethod = aMethod;
       
   255 	}
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CMediaDataClient::SetRedirected()
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 void CMediaDataClient::SetRedirected( TBool aRedirected )
       
   262 	{
       
   263 	iRedirected = aRedirected;
       
   264 	}
       
   265 
       
   266 // ---------------------------------------------------------
       
   267 // CMediaDataClient::SetDestFilenameL()
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 TBool CMediaDataClient::SetDestFilenameL( const TDesC& aDestFilename )
       
   271 	{
       
   272 	return SetStringAttrL( iDestFilename, aDestFilename, KMaxFileName );
       
   273 	}
       
   274 	
       
   275 // ---------------------------------------------------------
       
   276 // CMediaDataClient::SetTempFilenameL()
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 TBool CMediaDataClient::SetTempFilenameL( const TDesC& aTempFilename )
       
   280 	{
       
   281 	return SetStringAttrL( iTempFilename, aTempFilename, KMaxFileName );
       
   282 	}
       
   283 
       
   284 // ---------------------------------------------------------
       
   285 // CMediaDataClient::SetDownloadedSize()
       
   286 // ---------------------------------------------------------
       
   287 //
       
   288 TBool CMediaDataClient::SetDownloadedSize( TInt aDownloadedSize )
       
   289 	{
       
   290 	if( aDownloadedSize <= 0 )
       
   291         {
       
   292         return EFalse;
       
   293         }
       
   294     iDownloadedSize = aDownloadedSize;
       
   295     return ETrue;
       
   296 	}
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CMediaDataClient::SetDesRemovable()
       
   300 // ---------------------------------------------------------
       
   301 //
       
   302 void CMediaDataClient::SetDesRemovable( TBool aDesRemovable )
       
   303 	{
       
   304 	iDesRemovable = aDesRemovable;
       
   305 	}
       
   306 
       
   307 // ---------------------------------------------------------
       
   308 // CMediaDataClient::SetLastErrorId()
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 void CMediaDataClient::SetLastErrorId( TInt aLastErrorId )
       
   312 	{
       
   313 	iLastErrorId = aLastErrorId;
       
   314 	}
       
   315 
       
   316 // ---------------------------------------------------------
       
   317 // CMediaDataClient::SetGlobalErrorId()
       
   318 // ---------------------------------------------------------
       
   319 //
       
   320 void CMediaDataClient::SetGlobalErrorId( TInt aGlobalErrorId )
       
   321 	{
       
   322 	iGlobalErrorId = aGlobalErrorId;
       
   323 	}
       
   324 
       
   325 // ---------------------------------------------------------
       
   326 // CMediaDataClient::SetPausable()
       
   327 // ---------------------------------------------------------
       
   328 //
       
   329 void CMediaDataClient::SetPausable( TBool aPausable )
       
   330 	{
       
   331 	iPausable = aPausable;
       
   332 	}
       
   333 	
       
   334 // ---------------------------------------------------------
       
   335 // CMediaDataClient::SetStringAttrL()
       
   336 // ---------------------------------------------------------
       
   337 //
       
   338 TBool CMediaDataClient::SetStringAttrL
       
   339 ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   340     {
       
   341     if ( aString.Length() > aMaxLength )
       
   342         {
       
   343         return EFalse;
       
   344         }
       
   345     HBufC* buf = aString.AllocL();
       
   346     delete aBuf;
       
   347     aBuf = buf;
       
   348     return ETrue;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------
       
   352 // CMediaDataClient::SetStringAttrL()
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TBool CMediaDataClient::SetStringAttrL
       
   356 ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   357     {
       
   358     if ( aString.Length() > aMaxLength )
       
   359         {
       
   360         return EFalse;
       
   361         }
       
   362         
       
   363     HBufC8* buf = CodUtil::ConvertL( aString );
       
   364     delete aBuf;
       
   365     aBuf = buf;
       
   366     return ETrue;
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CMediaDataClient::SetStringAttrL()
       
   371 // ---------------------------------------------------------
       
   372 //
       
   373 TBool CMediaDataClient::SetStringAttrL
       
   374 ( HBufC8*& aBuf, const TDesC8& aString, TInt aMaxLength )
       
   375     {
       
   376     if ( aString.Length() > aMaxLength )
       
   377         {
       
   378         return EFalse;
       
   379         }
       
   380     HBufC8* buf = aString.AllocL();
       
   381     delete aBuf;
       
   382     aBuf = buf;
       
   383     return ETrue;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------
       
   387 // CMediaDataClient::MarshalDataL()
       
   388 // ---------------------------------------------------------
       
   389 //
       
   390 HBufC8* CMediaDataClient::MarshalDataL() const
       
   391     {
       
   392     TInt bufLen = Bytes();      // Size of class including iMediaArray elements.
       
   393                                 //  Note that this includes actual bytes occupied by
       
   394                                 //  contents of descriptors and pointers.
       
   395                                 
       
   396     bufLen += sizeof(TInt);  	// We include the count of elements in iTypes array
       
   397                                 //  while externalizing.
       
   398                                 
       
   399     
       
   400     // Dynamic data buffer
       
   401     CBufFlat* buf = CBufFlat::NewL(bufLen);
       
   402     CleanupStack::PushL(buf);
       
   403     // Stream over the buffer
       
   404     RBufWriteStream stream(*buf);
       
   405     CleanupClosePushL(stream);
       
   406     
       
   407     ExternalizeL(stream);
       
   408     CleanupStack::PopAndDestroy(); //stream
       
   409     
       
   410     // Create a heap descriptor from the buffer
       
   411     HBufC8* des = HBufC8::NewL(buf->Size());
       
   412     TPtr8 ptr(des->Des());
       
   413     buf->Read(0, ptr, buf->Size());
       
   414     CleanupStack::PopAndDestroy(); //buf
       
   415     
       
   416     return des;
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------
       
   420 // CMediaDataClient::ExternalizeL()
       
   421 // ---------------------------------------------------------
       
   422 //	
       
   423 void CMediaDataClient::ExternalizeL(RWriteStream& aStream) const
       
   424     {
       
   425     // iName
       
   426     if (iName)
       
   427         aStream << *iName;
       
   428     else
       
   429         aStream << KNullDesC;
       
   430     
       
   431     // iUrl
       
   432     if (iUrl)
       
   433         aStream << *iUrl;
       
   434     else
       
   435         aStream << KNullDesC;
       
   436     
       
   437     // iSize
       
   438     aStream.WriteUint32L(iSize);
       
   439     
       
   440     // Number of elements in iTypes array
       
   441     if (iTypes)
       
   442         {
       
   443         TInt count = iTypes->MdcaCount();
       
   444         aStream.WriteInt32L(count);
       
   445         // Elements of iTypes array
       
   446         for (TInt index = 0; index < count; ++index)
       
   447             aStream << iTypes->MdcaPoint(index);
       
   448         }
       
   449     else
       
   450         {
       
   451         aStream.WriteInt32L(0);
       
   452         }
       
   453     
       
   454     // iIcon
       
   455     if (iIcon)
       
   456         aStream << *iIcon;
       
   457     else
       
   458         aStream << KNullDesC;
       
   459     
       
   460     // iSourceUri
       
   461     if (iSourceUri)
       
   462         aStream << *iSourceUri;
       
   463     else
       
   464         aStream << KNullDesC;
       
   465     
       
   466     // iProgressiveDl
       
   467     aStream.WriteInt32L(iProgressiveDl);
       
   468     
       
   469     // iState
       
   470     aStream.WriteInt32L(iState);
       
   471     
       
   472     // iResult
       
   473     aStream.WriteInt32L(iResult);
       
   474     
       
   475     // iRedirUrl
       
   476     if (iRedirUrl)
       
   477         aStream << *iRedirUrl;
       
   478     else
       
   479         aStream << KNullDesC;
       
   480     
       
   481     // iMethod
       
   482     aStream.WriteInt32L(iMethod);
       
   483     
       
   484     // iRedirected
       
   485     aStream.WriteInt32L(iRedirected);
       
   486     
       
   487     // iDestFilename
       
   488     if (iIcon)
       
   489         aStream << *iDestFilename;
       
   490     else
       
   491         aStream << KNullDesC;
       
   492     
       
   493     // iDownloadedSize
       
   494     aStream.WriteInt32L(iDownloadedSize);
       
   495     
       
   496     // iDesRemovable
       
   497     aStream.WriteInt32L(iDesRemovable);
       
   498     
       
   499     // iLastErrorId
       
   500     aStream.WriteInt32L(iLastErrorId);
       
   501     
       
   502     // iGlobalErrorId
       
   503     aStream.WriteInt32L(iGlobalErrorId);
       
   504     
       
   505     // iPausable
       
   506     aStream.WriteInt32L(iPausable);
       
   507     }
       
   508 
       
   509 void CMediaDataClient::InternalizeL(RReadStream& /*aStream*/)
       
   510     {
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------
       
   514 // CDownloadDataClient::NewL()
       
   515 // ---------------------------------------------------------
       
   516 //
       
   517 CDownloadDataClient* CDownloadDataClient::NewL()
       
   518     {
       
   519     CDownloadDataClient* data = new (ELeave) CDownloadDataClient();
       
   520     CleanupStack::PushL( data );
       
   521     data->ConstructL();
       
   522     CleanupStack::Pop(); //data
       
   523     return data;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------
       
   527 // CDownloadDataClient::NewLC()
       
   528 // ---------------------------------------------------------
       
   529 //
       
   530 CDownloadDataClient* CDownloadDataClient::NewLC()
       
   531     {
       
   532     CDownloadDataClient* data = new (ELeave) CDownloadDataClient();
       
   533     CleanupStack::PushL( data );
       
   534     data->ConstructL();
       
   535     return data;
       
   536     }
       
   537 
       
   538 // ---------------------------------------------------------
       
   539 // CDownloadDataClient::~CDownloadDataClient()
       
   540 // ---------------------------------------------------------
       
   541 //
       
   542 CDownloadDataClient::~CDownloadDataClient()
       
   543     {
       
   544     delete iName;
       
   545     delete iIcon;
       
   546 	delete iUpdatedDDUri;
       
   547     
       
   548     iMediaArray.ResetAndDestroy();
       
   549     }
       
   550 
       
   551 // ---------------------------------------------------------
       
   552 // CDownloadDataClient::ConstructL()
       
   553 // ---------------------------------------------------------
       
   554 //
       
   555 void CDownloadDataClient::ConstructL()
       
   556     {
       
   557     iName = HBufC::NewL( 0 );
       
   558     iSize = 0;
       
   559     iIcon = HBufC8::NewL( 0 );
       
   560 	iUpdatedDDUri = HBufC8::NewL( 0 );
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------
       
   564 // CDownloadDataClient::Bytes()
       
   565 // ---------------------------------------------------------
       
   566 //
       
   567 TInt CDownloadDataClient::Bytes() const
       
   568     {
       
   569     TInt bytes = 0;
       
   570     
       
   571     bytes += iName->Size();
       
   572     bytes += sizeof(iSize);
       
   573     bytes += iIcon->Size();
       
   574     bytes += iUpdatedDDUri->Size();
       
   575     
       
   576     // iMediaArray elements 
       
   577     for (TInt index = 0; index < iMediaArray.Count(); ++index)
       
   578         bytes += iMediaArray[index]->Bytes();
       
   579     
       
   580     return bytes;
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------
       
   584 // CDownloadDataClient::SetNameL()
       
   585 // ---------------------------------------------------------
       
   586 //
       
   587 TBool CDownloadDataClient::SetNameL( const TDesC& aName )
       
   588     {
       
   589     return SetStringAttrL( iName, aName, COD_NAME_MAX_LEN );
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------
       
   593 // CDownloadDataClient::SetSize()
       
   594 // ---------------------------------------------------------
       
   595 //
       
   596 TBool CDownloadDataClient::SetSize( TUint aSize )
       
   597     {
       
   598     if( aSize <= 0 )
       
   599         {
       
   600         return EFalse;
       
   601         }
       
   602     iSize = aSize;
       
   603     return ETrue;
       
   604     }
       
   605 
       
   606 // ---------------------------------------------------------
       
   607 // CDownloadDataClient::SetIconL()
       
   608 // ---------------------------------------------------------
       
   609 //
       
   610 TBool CDownloadDataClient::SetIconL( const TDesC8& aIcon )
       
   611     {
       
   612     return SetStringAttrL( iIcon, aIcon, COD_ICON_MAX_LEN );
       
   613     }
       
   614     
       
   615 // ---------------------------------------------------------
       
   616 // CDownloadDataClient::SetUpdatedDDURI()
       
   617 // ---------------------------------------------------------
       
   618 //
       
   619 TBool CDownloadDataClient::SetUpdatedDDURI( const TDesC8& aUrl)
       
   620     {
       
   621     return SetStringAttrL( iUpdatedDDUri, aUrl, COD_URL_MAX_LEN );
       
   622     }    
       
   623 
       
   624 // ---------------------------------------------------------
       
   625 // CDownloadDataClient::SetStringAttrL()
       
   626 // ---------------------------------------------------------
       
   627 //
       
   628 TBool CDownloadDataClient::SetStringAttrL
       
   629 ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   630     {
       
   631     if ( aString.Length() > aMaxLength )
       
   632         {
       
   633         return EFalse;
       
   634         }
       
   635     HBufC* buf = aString.AllocL();
       
   636     delete aBuf;
       
   637     aBuf = buf;
       
   638     return ETrue;
       
   639     }
       
   640 
       
   641 // ---------------------------------------------------------
       
   642 // CDownloadDataClient::SetStringAttrL()
       
   643 // ---------------------------------------------------------
       
   644 //
       
   645 TBool CDownloadDataClient::SetStringAttrL
       
   646 ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   647     {
       
   648     if ( aString.Length() > aMaxLength )
       
   649         {
       
   650         return EFalse;
       
   651         }
       
   652     HBufC8* buf = CodUtil::ConvertL( aString );
       
   653     delete aBuf;
       
   654     aBuf = buf;
       
   655     return ETrue;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CDownloadDataClient::SetStringAttrL()
       
   660 // ---------------------------------------------------------
       
   661 //
       
   662 TBool CDownloadDataClient::SetStringAttrL
       
   663 ( HBufC8*& aBuf, const TDesC8& aString, TInt aMaxLength )
       
   664     {
       
   665     if ( aString.Length() > aMaxLength )
       
   666         {
       
   667         return EFalse;
       
   668         }
       
   669     HBufC8* buf = aString.AllocL();
       
   670     delete aBuf;
       
   671     aBuf = buf;
       
   672     return ETrue;
       
   673     }
       
   674 	
       
   675 // ---------------------------------------------------------
       
   676 // CDownloadDataClient::AppendMediaData()
       
   677 // ---------------------------------------------------------
       
   678 //
       
   679 TInt CDownloadDataClient::AppendMediaData( CMediaDataClient *aMO )
       
   680     {
       
   681     iMediaArray.AppendL( aMO );
       
   682     // return item index
       
   683     return iMediaArray.Count();    
       
   684     }
       
   685     
       
   686 // ---------------------------------------------------------
       
   687 // CDownloadDataClient::operator[]
       
   688 // ---------------------------------------------------------
       
   689 //
       
   690 
       
   691 CMediaDataBase* CDownloadDataClient::operator[]( TInt aIndex )
       
   692     {
       
   693     //Check if the media object exits at specified index. Return the same if it is.
       
   694     if( aIndex >= 0 && aIndex < iMediaArray.Count() )
       
   695         {
       
   696         return iMediaArray[aIndex];
       
   697         }
       
   698     return NULL;    
       
   699     }
       
   700 
       
   701 // ---------------------------------------------------------
       
   702 // CDownloadDataClient::operator[]
       
   703 // ---------------------------------------------------------
       
   704 //
       
   705 
       
   706 CMediaDataBase* CDownloadDataClient::operator[]( TInt aIndex ) const
       
   707     {
       
   708     //Check if the media object exits at specified index. Return the same if it is.
       
   709     if( aIndex >= 0 && aIndex < iMediaArray.Count() )
       
   710         {
       
   711         return iMediaArray[aIndex];
       
   712         }
       
   713     return NULL;    
       
   714     }
       
   715 
       
   716 // ---------------------------------------------------------
       
   717 // CDownloadDataClient::MarshalDataL()
       
   718 // ---------------------------------------------------------
       
   719 //
       
   720 HBufC8* CDownloadDataClient::MarshalDataL() const
       
   721     {
       
   722     TInt bufLen = Bytes();      // Size of class including iMediaArray elements.
       
   723                                 //  Note that this includes actual bytes occupied by
       
   724                                 //  contents of descriptors and pointers.
       
   725                                 
       
   726     bufLen += sizeof(TInt);  // We include the count of elements in iMediaArray
       
   727                                 //  while externalizing.
       
   728                                 
       
   729     bufLen += sizeof(TInt) * iMediaArray.Count();
       
   730                                 // iMediaArray has an array iTypes. We are including
       
   731                                 //  count of elements in iTypes array while externalizing
       
   732                                 //  each element of iMediaArray.
       
   733     
       
   734     // Dynamic data buffer
       
   735     CBufFlat* buf = CBufFlat::NewL(bufLen);
       
   736     CleanupStack::PushL(buf);
       
   737     // Stream over the buffer
       
   738     RBufWriteStream stream(*buf);
       
   739     CleanupClosePushL(stream);
       
   740     
       
   741     ExternalizeL(stream);
       
   742     CleanupStack::PopAndDestroy(); //stream
       
   743     
       
   744     // Create a heap descriptor from the buffer
       
   745     HBufC8* des = HBufC8::NewL(buf->Size());
       
   746     TPtr8 ptr(des->Des());
       
   747     buf->Read(0, ptr, buf->Size());
       
   748     CleanupStack::PopAndDestroy(); //buf
       
   749     
       
   750     return des;
       
   751     }
       
   752 
       
   753 // ---------------------------------------------------------
       
   754 // CDownloadDataClient::ExternalizeL()
       
   755 // ---------------------------------------------------------
       
   756 //
       
   757 void CDownloadDataClient::ExternalizeL(RWriteStream& aStream) const
       
   758     {
       
   759     // iName
       
   760     if (iName)
       
   761         aStream << *iName;
       
   762     else
       
   763         aStream << KNullDesC;
       
   764     
       
   765     // iSize
       
   766     aStream.WriteUint32L(iSize);
       
   767     
       
   768     // iIcon
       
   769     if (iIcon)
       
   770         aStream << *iIcon;
       
   771     else
       
   772         aStream << KNullDesC;
       
   773     
       
   774     // iUpdatedDDUri
       
   775     if (iUpdatedDDUri)
       
   776         aStream << *iUpdatedDDUri;
       
   777     else
       
   778         aStream << KNullDesC;
       
   779     
       
   780     // iMediaArray elements 
       
   781     TInt count = iMediaArray.Count();
       
   782     aStream.WriteInt32L(count);
       
   783     for (TInt index = 0; index < count; ++index)
       
   784         iMediaArray[index]->ExternalizeL(aStream);
       
   785    
       
   786     }