browserutilities/downloadmgr/DownloadMgrServEng/Src/DownloadDataServ.cpp
changeset 0 dd21522fd290
child 10 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-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 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <s32mem.h>
       
    22 #include "DownloadDataServ.h"
       
    23 
       
    24 
       
    25 // CONSTANTS
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------
       
    29 // CMediaDataServ::NewL()
       
    30 // Two-phase Constructor - Creates object from stream
       
    31 // ---------------------------------------------------------
       
    32 // 
       
    33 CMediaDataServ* CMediaDataServ::NewL(RReadStream& aStreamData)
       
    34     {
       
    35     CMediaDataServ* data = new (ELeave) CMediaDataServ();
       
    36     CleanupStack::PushL(data);
       
    37     data->InternalizeL(aStreamData);
       
    38     CleanupStack::Pop(); //data
       
    39     return data;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CMediaDataServ::NewL()
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 CMediaDataServ* CMediaDataServ::NewL(const TDesC8& aStreamData)
       
    47     {
       
    48     CMediaDataServ* data = new (ELeave) CMediaDataServ();
       
    49     CleanupStack::PushL( data );
       
    50     RDesReadStream stream(aStreamData);
       
    51     CleanupClosePushL(stream);
       
    52     data->InternalizeL(stream);
       
    53     CleanupStack::PopAndDestroy(); //stream
       
    54     CleanupStack::Pop(); //data
       
    55     return data;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CMediaDataServ::~CMediaDataServ()
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CMediaDataServ::~CMediaDataServ()
       
    63     {
       
    64     delete iName;
       
    65     delete iUrl;
       
    66     delete iTypes;
       
    67     delete iIcon;
       
    68     delete iSourceUri;
       
    69     delete iRedirUrl;
       
    70     delete iDestFilename;
       
    71     delete iTempFilename;
       
    72     }
       
    73 
       
    74 // CMediaDataServ::Bytes()
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 TInt CMediaDataServ::Bytes() const
       
    78     {
       
    79     return 0;
       
    80     }
       
    81     
       
    82 // ---------------------------------------------------------
       
    83 // CMediaDataServ::SetNameL()
       
    84 // ---------------------------------------------------------
       
    85 //
       
    86 TBool CMediaDataServ::SetNameL( const TDesC& aName )
       
    87     {
       
    88     return SetStringAttrL( iName, aName, COD_NAME_MAX_LEN );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CMediaDataServ::SetUrlL()
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 TBool CMediaDataServ::SetUrlL( const TDesC8& aUrl )
       
    96     {
       
    97     return SetStringAttrL( iUrl, aUrl, COD_URL_MAX_LEN );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CMediaDataServ::SetSize()
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 TBool CMediaDataServ::SetSize( TUint aSize )
       
   105     {
       
   106     if( aSize <= 0 )
       
   107         {
       
   108         return EFalse;
       
   109         }
       
   110     iSize = aSize;
       
   111     return ETrue;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CMediaDataServ::SetTypeL()
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 TBool CMediaDataServ::SetTypeL( const TDesC8& aType )
       
   119     {
       
   120     // Backwards-compatible deprecated method.
       
   121     iTypes->Reset();    // Replace all, support only one type.
       
   122     return AddTypeL( aType );
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------
       
   126 // CMediaDataServ::AddTypeL()
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 TBool CMediaDataServ::AddTypeL( const TDesC8& aType )
       
   130     {
       
   131     if ( aType.Length() > COD_TYPE_MAX_LEN || !aType.Length() )
       
   132         {
       
   133         return EFalse;
       
   134         }
       
   135     HBufC8* type8 = aType.AllocLC();
       
   136     iTypes->AppendL( *type8 );
       
   137     CleanupStack::PopAndDestroy(); //type8
       
   138     return ETrue;
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------
       
   142 // CMediaDataServ::ResetTypes()
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void CMediaDataServ::ResetTypes()
       
   146 	{
       
   147 	iTypes->Reset();
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // CMediaDataServ::SetIconL()
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 TBool CMediaDataServ::SetIconL( const TDesC8& aIcon )
       
   155     {
       
   156     return SetStringAttrL( iIcon, aIcon, COD_ICON_MAX_LEN );
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------
       
   160 // CMediaDataServ::SetSourceUriL()
       
   161 // ---------------------------------------------------------
       
   162 //
       
   163 void CMediaDataServ::SetSourceUriL( const TDesC8& aSourceUri )
       
   164     {
       
   165     HBufC8* buf = aSourceUri.AllocL();
       
   166     delete iSourceUri;
       
   167     iSourceUri = buf;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CMediaDataServ::SetProgressiveDownload()
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CMediaDataServ::SetProgressiveDownload( TBool aProgressiveDl )
       
   175     {
       
   176     iProgressiveDl = aProgressiveDl;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CMediaDataServ::SetState()
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CMediaDataServ::SetState( TMediaObjectState aState )
       
   184     {
       
   185     iState = aState;
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CMediaDataServ::SetResult()
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CMediaDataServ::SetResult( TInt aResult )
       
   193     {
       
   194     iResult = aResult;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CMediaDataServ::SetRedirUrlL()
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 TBool CMediaDataServ::SetRedirUrlL( const TDesC8& aRedirUrl )
       
   202 	{
       
   203 	return SetStringAttrL( iRedirUrl, aRedirUrl, COD_URL_MAX_LEN );
       
   204 	}
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CMediaDataServ::SetMethod()
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 void CMediaDataServ::SetMethod( TInt aMethod )
       
   211 	{
       
   212 	iMethod = aMethod;
       
   213 	}
       
   214 
       
   215 // ---------------------------------------------------------
       
   216 // CMediaDataServ::SetRedirected()
       
   217 // ---------------------------------------------------------
       
   218 //
       
   219 void CMediaDataServ::SetRedirected( TBool aRedirected )
       
   220 	{
       
   221 	iRedirected = aRedirected;
       
   222 	}
       
   223 
       
   224 // ---------------------------------------------------------
       
   225 // CMediaDataServ::SetDestFilenameL()
       
   226 // ---------------------------------------------------------
       
   227 //
       
   228 TBool CMediaDataServ::SetDestFilenameL( const TDesC& aDestFilename )
       
   229 	{
       
   230 	return SetStringAttrL( iDestFilename, aDestFilename, KMaxFileName );
       
   231 	}
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CMediaDataServ::SetDownloadedSize()
       
   235 // ---------------------------------------------------------
       
   236 //
       
   237 TBool CMediaDataServ::SetDownloadedSize( TInt aDownloadedSize )
       
   238 	{
       
   239 	if( aDownloadedSize <= 0 )
       
   240         {
       
   241         return EFalse;
       
   242         }
       
   243     iDownloadedSize = aDownloadedSize;
       
   244     return ETrue;
       
   245 	}
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CMediaDataServ::SetDesRemovable()
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 void CMediaDataServ::SetDesRemovable( TBool aDesRemovable )
       
   252 	{
       
   253 	iDesRemovable = aDesRemovable;
       
   254 	}
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // CMediaDataServ::SetLastErrorId()
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 void CMediaDataServ::SetLastErrorId( TInt aLastErrorId )
       
   261 	{
       
   262 	iLastErrorId = aLastErrorId;
       
   263 	}
       
   264 
       
   265 // ---------------------------------------------------------
       
   266 // CMediaDataServ::SetGlobalErrorId()
       
   267 // ---------------------------------------------------------
       
   268 //
       
   269 void CMediaDataServ::SetGlobalErrorId( TInt aGlobalErrorId )
       
   270 	{
       
   271 	iGlobalErrorId = aGlobalErrorId;
       
   272 	}
       
   273 
       
   274 // ---------------------------------------------------------
       
   275 // CMediaDataServ::SetPausable()
       
   276 // ---------------------------------------------------------
       
   277 //
       
   278 void CMediaDataServ::SetPausable( TBool aPausable )
       
   279 	{
       
   280 	iPausable = aPausable;
       
   281 	}
       
   282 	
       
   283 // ---------------------------------------------------------
       
   284 // CMediaDataServ::SetStringAttrL()
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 TBool CMediaDataServ::SetStringAttrL
       
   288 ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   289     {
       
   290     if ( aString.Length() > aMaxLength )
       
   291         {
       
   292         return EFalse;
       
   293         }
       
   294     HBufC* buf = aString.AllocL();
       
   295     delete aBuf;
       
   296     aBuf = buf;
       
   297     return ETrue;
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------
       
   301 // CMediaDataServ::SetStringAttrL()
       
   302 // ---------------------------------------------------------
       
   303 //
       
   304 TBool CMediaDataServ::SetStringAttrL
       
   305 ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   306     {
       
   307     if ( aString.Length() > aMaxLength )
       
   308         {
       
   309         return EFalse;
       
   310         }
       
   311         
       
   312     HBufC8* buf = HBufC8::NewL( aString.Length() );
       
   313     buf->Des().Copy( aString );
       
   314     delete aBuf;
       
   315     aBuf = buf;
       
   316     return ETrue;
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------
       
   320 // CMediaDataServ::SetStringAttrL()
       
   321 // ---------------------------------------------------------
       
   322 //
       
   323 TBool CMediaDataServ::SetStringAttrL
       
   324 ( HBufC8*& aBuf, const TDesC8& aString, TInt aMaxLength )
       
   325     {
       
   326     if ( aString.Length() > aMaxLength )
       
   327         {
       
   328         return EFalse;
       
   329         }
       
   330     HBufC8* buf = aString.AllocL();
       
   331     delete aBuf;
       
   332     aBuf = buf;
       
   333     return ETrue;
       
   334     }
       
   335     
       
   336 // ---------------------------------------------------------
       
   337 // CMediaDataServ::ExternalizeL()
       
   338 // ---------------------------------------------------------
       
   339 //	
       
   340 void CMediaDataServ::ExternalizeL(RWriteStream& /*aStream*/) const
       
   341     {
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------
       
   345 // CMediaDataServ::InternalizeL()
       
   346 // ---------------------------------------------------------
       
   347 //	
       
   348 void CMediaDataServ::InternalizeL(RReadStream& aStream)
       
   349     {
       
   350     iName = HBufC::NewL(aStream, COD_NAME_MAX_LEN);
       
   351     iUrl = HBufC8::NewL(aStream, COD_URL_MAX_LEN);
       
   352     iSize = aStream.ReadUint32L();
       
   353     
       
   354     // Number of elements in iTypes array
       
   355     TInt count = aStream.ReadInt32L();
       
   356     // Fill elements of iTypes array
       
   357     iTypes = new (ELeave) CDesC8ArrayFlat( KTypeGranularity );
       
   358     for (TInt index = 0; index < count; ++index)
       
   359         {
       
   360         HBufC8* des8 = HBufC8::NewLC(aStream, COD_TYPE_MAX_LEN);
       
   361         iTypes->AppendL(*des8);
       
   362         CleanupStack::Pop(); //des8
       
   363         }
       
   364     
       
   365     iIcon = HBufC8::NewL(aStream, COD_ICON_MAX_LEN);
       
   366     iSourceUri = HBufC8::NewL(aStream, COD_URL_MAX_LEN);
       
   367     iProgressiveDl = aStream.ReadInt32L();    
       
   368     iState = static_cast<TMediaObjectState> (aStream.ReadInt32L());
       
   369     iResult = aStream.ReadInt32L();
       
   370     iRedirUrl = HBufC8::NewL(aStream, COD_URL_MAX_LEN);
       
   371     iMethod = aStream.ReadInt32L();
       
   372     iRedirected = aStream.ReadInt32L();
       
   373     iDestFilename = HBufC::NewL(aStream, KMaxFileName);
       
   374     iDownloadedSize = aStream.ReadInt32L();
       
   375     iDesRemovable = aStream.ReadInt32L();
       
   376     iLastErrorId = aStream.ReadInt32L();
       
   377     iGlobalErrorId = aStream.ReadInt32L();
       
   378     iPausable = aStream.ReadInt32L();
       
   379     
       
   380     
       
   381     iTempFilename = HBufC::NewL(KMaxFileName);
       
   382     }  
       
   383     
       
   384 // ---------------------------------------------------------
       
   385 // CMediaDataServ::SetTempFilenameL()
       
   386 // ---------------------------------------------------------
       
   387 //
       
   388 TBool CMediaDataServ::SetTempFilenameL( const TDesC& aTempFilename )
       
   389 	{
       
   390 	return SetStringAttrL( iTempFilename, aTempFilename, KMaxFileName );
       
   391 	}
       
   392 	    
       
   393 // ---------------------------------------------------------
       
   394 // CDownloadDataServ::NewL()
       
   395 // ---------------------------------------------------------
       
   396 //
       
   397 CDownloadDataServ* CDownloadDataServ::NewL(const TDesC8& aStreamData)
       
   398     {
       
   399     CDownloadDataServ* data = new (ELeave) CDownloadDataServ();
       
   400     CleanupStack::PushL( data );
       
   401     RDesReadStream stream(aStreamData);
       
   402     CleanupClosePushL(stream);
       
   403     data->InternalizeL(stream);
       
   404     CleanupStack::PopAndDestroy(); //stream
       
   405     CleanupStack::Pop(); //data
       
   406     return data;
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------
       
   410 // CDownloadDataServ::~CDownloadDataServ()
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 CDownloadDataServ::~CDownloadDataServ()
       
   414     {
       
   415     delete iName;
       
   416     delete iIcon;
       
   417 	delete iUpdatedDDUri;
       
   418     
       
   419     iMediaArray.ResetAndDestroy();
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------
       
   423 // CDownloadDataServ::operator[]
       
   424 // ---------------------------------------------------------
       
   425 //
       
   426 CMediaDataBase* CDownloadDataServ::operator[]( TInt aIndex )
       
   427     {
       
   428     //Check if the media object exits at specified index. Return the same if it is.
       
   429     if( aIndex > 0 && aIndex <= iMediaArray.Count() )
       
   430         {
       
   431         return iMediaArray[aIndex-1];
       
   432         }
       
   433     return NULL;    
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // CDownloadDataServ::operator[]
       
   438 // ---------------------------------------------------------
       
   439 //
       
   440 CMediaDataBase* CDownloadDataServ::operator[]( TInt aIndex ) const
       
   441     {
       
   442     //Check if the media object exits at specified index. Return the same if it is.
       
   443     if( aIndex > 0 && aIndex <= iMediaArray.Count() )
       
   444         {
       
   445         return iMediaArray[aIndex-1];
       
   446         }
       
   447     return NULL;    
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CDownloadDataServ::InternalizeL()
       
   452 // ---------------------------------------------------------
       
   453 //
       
   454 void CDownloadDataServ::InternalizeL(RReadStream& aStream)
       
   455     {
       
   456     iName = HBufC::NewL(aStream, COD_NAME_MAX_LEN);
       
   457     iSize = aStream.ReadUint32L();
       
   458     iIcon = HBufC8::NewL(aStream, COD_ICON_MAX_LEN);
       
   459     iUpdatedDDUri = HBufC8::NewL(aStream, COD_URL_MAX_LEN);
       
   460     
       
   461     // iMediaObjects array elements
       
   462     iMediaArray.Reset();
       
   463     TInt count = aStream.ReadInt32L();
       
   464     for (TInt index = 0; index < count; ++index)
       
   465         {
       
   466         CMediaDataServ* mediaData = CMediaDataServ::NewL(aStream);
       
   467         iMediaArray.AppendL(mediaData);
       
   468         }
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------
       
   472 // CDownloadDataServ::SetStringAttrL()
       
   473 // ---------------------------------------------------------
       
   474 //
       
   475 TBool CDownloadDataServ::SetStringAttrL
       
   476 ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   477     {
       
   478     if ( aString.Length() > aMaxLength )
       
   479         {
       
   480         return EFalse;
       
   481         }
       
   482     HBufC* buf = aString.AllocL();
       
   483     delete aBuf;
       
   484     aBuf = buf;
       
   485     return ETrue;
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------
       
   489 // CDownloadDataServ::SetStringAttrL()
       
   490 // ---------------------------------------------------------
       
   491 //
       
   492 TBool CDownloadDataServ::SetStringAttrL
       
   493 ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   494     {
       
   495     if ( aString.Length() > aMaxLength )
       
   496         {
       
   497         return EFalse;
       
   498         }
       
   499         
       
   500     HBufC8* buf = HBufC8::NewL( aString.Length() );
       
   501     buf->Des().Copy( aString );
       
   502     delete aBuf;
       
   503     aBuf = buf;
       
   504     return ETrue;
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------
       
   508 // CDownloadDataServ::SetStringAttrL()
       
   509 // ---------------------------------------------------------
       
   510 //
       
   511 TBool CDownloadDataServ::SetStringAttrL
       
   512 ( HBufC8*& aBuf, const TDesC8& aString, TInt aMaxLength )
       
   513     {
       
   514     if ( aString.Length() > aMaxLength )
       
   515         {
       
   516         return EFalse;
       
   517         }
       
   518     HBufC8* buf = aString.AllocL();
       
   519     delete aBuf;
       
   520     aBuf = buf;
       
   521     return ETrue;
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------
       
   525 // CDownloadDataServ::SetNameL()
       
   526 // ---------------------------------------------------------
       
   527 //
       
   528 TBool CDownloadDataServ::SetNameL( const TDesC& aName )
       
   529     {
       
   530     return SetStringAttrL( iName, aName, COD_NAME_MAX_LEN );
       
   531     }
       
   532 
       
   533 //  End of File