codhandler/codeng/src/CodData.cpp
changeset 0 dd21522fd290
child 36 0ed94ceaa377
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 CCodData.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "CodData.h"
       
    24 #include "CodDefs.h"
       
    25 #include "CodUtil.h"
       
    26 #include <badesca.h>
       
    27 #include "FileExt.h"
       
    28 #include "HttpDownloadData.h"
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CCodData::NewL()
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CCodData* CCodData::NewL()
       
    38     {
       
    39     CCodData* data = new (ELeave) CCodData();
       
    40     CleanupStack::PushL( data );
       
    41     data->ConstructL();
       
    42     CleanupStack::Pop( data );
       
    43     return data;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CCodData::~CCodData()
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CCodData::~CCodData()
       
    51     {
       
    52     delete iName;
       
    53     delete iVendor;
       
    54     delete iDescription;
       
    55     delete iInstallNotify;
       
    56     delete iNextUrl;
       
    57     delete iNextUrlAtError;
       
    58     delete iInfoUrl;
       
    59     delete iPrice;
       
    60     delete iIcon;
       
    61     delete iVersion;
       
    62 	delete iUpdatedDDUri;
       
    63     delete iSourceUri;
       
    64     
       
    65     iMediaObjects.ResetAndDestroy();
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CCodData::IsValid()
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 EXPORT_C TBool CCodData::IsValid() const
       
    73     {
       
    74     TInt mediaObjectsValid = EFalse;
       
    75     
       
    76     //First check if all the media objects are valid
       
    77     //Also check total size is valid
       
    78     for( TInt i = 0; i < iMediaObjects.Count(); i++ )
       
    79         {
       
    80         mediaObjectsValid = iMediaObjects[i]->IsValid();
       
    81         if( !mediaObjectsValid ) break;
       
    82         }
       
    83     return ( iSize > 0 && mediaObjectsValid );
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CCodData::IsPostOrder()
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 EXPORT_C TBool CCodData::IsPostOrder() const
       
    91     {
       
    92     return iIsPostOrder;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CCodData::Reset()
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void CCodData::Reset()
       
   100     {
       
   101     iName->Des().Zero();
       
   102     iVendor->Des().Zero();
       
   103     iDescription->Des().Zero();
       
   104     iSize = 0;
       
   105     iInstallNotify->Des().Zero();
       
   106     iNextUrl->Des().Zero();
       
   107     iNextUrlAtError->Des().Zero();
       
   108     iInfoUrl->Des().Zero();
       
   109     iPrice->Des().Zero();
       
   110     iIcon->Des().Zero();
       
   111     iVersion->Des().Zero();
       
   112 	iIsPostOrder = EFalse;
       
   113 	iUpdatedDDUri->Des().Zero();
       
   114 	iSourceUri->Des().Zero();
       
   115 	iActiveDownload = 1;
       
   116     
       
   117     //Also reset all media objects values
       
   118     for( TInt i = 0; i < iMediaObjects.Count(); i++ )
       
   119         {
       
   120         iMediaObjects[i]->Reset();
       
   121         }	
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CCodData::Name()
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 EXPORT_C TPtrC CCodData::Name() const
       
   129     {
       
   130     return *iName;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CCodData::Vendor()
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 EXPORT_C TPtrC CCodData::Vendor() const
       
   138     {
       
   139     return *iVendor;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CCodData::Description()
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 EXPORT_C TPtrC CCodData::Description() const
       
   147     {
       
   148     return *iDescription;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CCodData::Size()
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 EXPORT_C TInt CCodData::Size() const
       
   156     {
       
   157     return iSize;
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CCodData::SuppressConfirm() 
       
   163 // ---------------------------------------------------------
       
   164 //
       
   165 EXPORT_C TInt CCodData::SuppressConfirm() const
       
   166     {
       
   167     return iSuppressConfirm;
       
   168     }
       
   169         
       
   170 // ---------------------------------------------------------
       
   171 // CCodData::InstallNotify()
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 EXPORT_C TPtrC8 CCodData::InstallNotify() const
       
   175     {
       
   176     return *iInstallNotify;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CCodData::NextUrl()
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 EXPORT_C TPtrC8 CCodData::NextUrl() const
       
   184     {
       
   185     return *iNextUrl;
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CCodData::NextUrlAtError()
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 EXPORT_C TPtrC8 CCodData::NextUrlAtError() const
       
   193     {
       
   194     return *iNextUrlAtError;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CCodData::InfoUrl
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 EXPORT_C TPtrC8 CCodData::InfoUrl() const
       
   202     {
       
   203     return *iInfoUrl;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CCodData::Price()
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 EXPORT_C TPtrC CCodData::Price() const
       
   211     {
       
   212     return *iPrice;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------
       
   216 // CCodData::Icon()
       
   217 // ---------------------------------------------------------
       
   218 //
       
   219 EXPORT_C TPtrC8 CCodData::Icon() const
       
   220     {
       
   221     return *iIcon;
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------
       
   225 // CCodData::Version()
       
   226 // ---------------------------------------------------------
       
   227 //
       
   228 EXPORT_C TPtrC CCodData::Version() const
       
   229     {
       
   230     return *iVersion;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CCodData::SourceUri()
       
   235 // ---------------------------------------------------------
       
   236 //
       
   237 EXPORT_C TPtrC8 CCodData::SourceUri() const
       
   238     {
       
   239     return *iSourceUri;
       
   240     }
       
   241 
       
   242 
       
   243 // ---------------------------------------------------------
       
   244 // CCodData::UpdatedDDURI()
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 EXPORT_C TPtrC8 CCodData::UpdatedDDUriL() const
       
   248     {
       
   249     return *iUpdatedDDUri;
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------
       
   254 // CCodData::CCodData()
       
   255 // ---------------------------------------------------------
       
   256 //
       
   257 CCodData::CCodData()
       
   258     {
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // CCodData::ConstructL()
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void CCodData::ConstructL()
       
   266     {
       
   267     iName = HBufC::NewL( 0 );
       
   268     iVendor = HBufC::NewL( 0 );
       
   269     iDescription = HBufC::NewL( 0 );
       
   270     iSize = 0;
       
   271     iInstallNotify = HBufC8::NewL( 0 );
       
   272     iNextUrl = HBufC8::NewL( 0 );
       
   273     iNextUrlAtError = HBufC8::NewL( 0 );
       
   274     iInfoUrl = HBufC8::NewL( 0 );
       
   275     iPrice = HBufC::NewL( 0 );
       
   276     iIcon = HBufC8::NewL( 0 );
       
   277     iVersion = HBufC::NewL( 0 );
       
   278     iSuppressConfirm = 0; 
       
   279 	iUpdatedDDUri = HBufC8::NewL( 0 );
       
   280 	iSourceUri = HBufC8::NewL( 0 );
       
   281 	iActiveDownload = 1;    
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------
       
   285 // CCodData::SetNameL()
       
   286 // ---------------------------------------------------------
       
   287 //
       
   288 TBool CCodData::SetNameL( const TDesC& aName )
       
   289     {
       
   290     return SetStringAttrL( iName, aName, COD_NAME_MAX_LEN );
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------
       
   294 // CCodData::SetVendorL()
       
   295 // ---------------------------------------------------------
       
   296 //
       
   297 TBool CCodData::SetVendorL( const TDesC& aVendor )
       
   298     {
       
   299     return SetStringAttrL( iVendor, aVendor, COD_VENDOR_MAX_LEN );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // CCodData::SetDescriptionL()
       
   304 // ---------------------------------------------------------
       
   305 //
       
   306 TBool CCodData::SetDescriptionL( const TDesC& aDescription )
       
   307     {
       
   308     return SetStringAttrL
       
   309         ( iDescription, aDescription, COD_DESCRIPTION_MAX_LEN );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------
       
   313 // CCodData::SetSize()
       
   314 // ---------------------------------------------------------
       
   315 //
       
   316 TBool CCodData::SetSize( TUint aSize )
       
   317     {
       
   318     if( aSize <= 0 )
       
   319         {
       
   320         return EFalse;
       
   321         }
       
   322     iSize = aSize;
       
   323     return ETrue;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CCodData::SetSuppressConfirm()
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 TBool CCodData::SetSuppressConfirm( TInt aSuppressConfirm )
       
   331     {
       
   332     if( aSuppressConfirm < ENever || aSuppressConfirm > EAlways )
       
   333         {
       
   334         return EFalse;
       
   335         }
       
   336         
       
   337     iSuppressConfirm  = aSuppressConfirm;
       
   338     return ETrue;
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------
       
   342 // CCodData::SetInstallNotifyL()
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 TBool CCodData::SetInstallNotifyL( const TDesC& aInstallNotify )
       
   346     {
       
   347     return SetStringAttrL
       
   348         ( iInstallNotify, aInstallNotify, COD_INSTALL_NOTIFY_MAX_LEN );
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------
       
   352 // CCodData::SetNextUrlL()
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TBool CCodData::SetNextUrlL( const TDesC& aNextUrl )
       
   356     {
       
   357     return SetStringAttrL( iNextUrl, aNextUrl, COD_NEXT_URL_MAX_LEN );
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CCodData::SetNextUrlAtErrorL()
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 TBool CCodData::SetNextUrlAtErrorL( const TDesC& aNextUrlAtError )
       
   365     {
       
   366     return SetStringAttrL
       
   367         ( iNextUrlAtError, aNextUrlAtError, COD_NEXT_URL_AT_ERROR_MAX_LEN );
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------
       
   371 // CCodData::SetInfoUrlL()
       
   372 // ---------------------------------------------------------
       
   373 //
       
   374 TBool CCodData::SetInfoUrlL( const TDesC& aInfoUrl )
       
   375     {
       
   376     return SetStringAttrL( iInfoUrl, aInfoUrl, COD_INFO_URL_MAX_LEN );
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------
       
   380 // CCodData::SetPriceL()
       
   381 // ---------------------------------------------------------
       
   382 //
       
   383 TBool CCodData::SetPriceL( const TDesC& aPrice )
       
   384     {
       
   385     return SetStringAttrL( iPrice, aPrice, COD_PRICE_MAX_LEN );
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------
       
   389 // CCodData::SetIconL()
       
   390 // ---------------------------------------------------------
       
   391 //
       
   392 TBool CCodData::SetIconL( const TDesC& aIcon )
       
   393     {
       
   394     return SetStringAttrL( iIcon, aIcon, COD_ICON_MAX_LEN );
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------
       
   398 // CCodData::SetVersionL()
       
   399 // ---------------------------------------------------------
       
   400 //
       
   401 TBool CCodData::SetVersionL( const TDesC& aVersion )
       
   402     {
       
   403     return SetStringAttrL( iVersion, aVersion, COD_VERSION_MAX_LEN );
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------
       
   407 // CCodData::SetSourceUriL()
       
   408 // ---------------------------------------------------------
       
   409 //
       
   410 void CCodData::SetSourceUriL( const TDesC8& aSourceUri )
       
   411     {
       
   412     HBufC8* buf = aSourceUri.AllocL();
       
   413     delete iSourceUri;
       
   414     iSourceUri = buf;
       
   415     }
       
   416 
       
   417 // ---------------------------------------------------------
       
   418 // CCodData::SetUpdatedDDURI()
       
   419 // ---------------------------------------------------------
       
   420 //
       
   421 TBool CCodData::SetUpdatedDDURI( const TDesC& aUrl)
       
   422     {
       
   423     return SetStringAttrL( iUpdatedDDUri, aUrl, COD_URL_MAX_LEN );
       
   424     }    
       
   425     
       
   426 // ---------------------------------------------------------
       
   427 // CCodData::SetActiveDownload()
       
   428 // ---------------------------------------------------------
       
   429 //
       
   430 void CCodData::SetActiveDownload( const TInt aMediaObjectId )
       
   431     {
       
   432     iActiveDownload = aMediaObjectId;
       
   433     }    
       
   434 
       
   435 // ---------------------------------------------------------
       
   436 // CCodData::SetOrderIsPost()
       
   437 // ---------------------------------------------------------
       
   438 //
       
   439 void CCodData::SetOrderIsPost( TBool aIsPostOrder )
       
   440     {
       
   441     iIsPostOrder = aIsPostOrder;
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------
       
   445 // CCodData::SetStringAttrL()
       
   446 // ---------------------------------------------------------
       
   447 //
       
   448 TBool CCodData::SetStringAttrL
       
   449 ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   450     {
       
   451     if ( aString.Length() > aMaxLength )
       
   452         {
       
   453         return EFalse;
       
   454         }
       
   455     HBufC* buf = aString.AllocL();
       
   456     delete aBuf;
       
   457     aBuf = buf;
       
   458     return ETrue;
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------
       
   462 // CCodData::SetStringAttrL()
       
   463 // ---------------------------------------------------------
       
   464 //
       
   465 TBool CCodData::SetStringAttrL
       
   466 ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength )
       
   467     {
       
   468     if ( aString.Length() > aMaxLength )
       
   469         {
       
   470         return EFalse;
       
   471         }
       
   472     HBufC8* buf = CodUtil::ConvertL( aString );
       
   473     delete aBuf;
       
   474     aBuf = buf;
       
   475     return ETrue;
       
   476     }
       
   477 // ---------------------------------------------------------
       
   478 // CCodData::AppendStorageInfoL()
       
   479 // ---------------------------------------------------------
       
   480 //
       
   481 void CCodData::AppendStorageInfoL(TPtr8& aBuf)const
       
   482 	{
       
   483 	TInt mediaCount = iMediaObjects.Count();
       
   484 	AppendBufL( aBuf,iName );
       
   485 	AppendBufL( aBuf,iVendor );
       
   486 	AppendBufL( aBuf,iNextUrl );
       
   487 	APPEND_BUF_INT( aBuf,iSize );
       
   488 	AppendBufL( aBuf,iPrice );
       
   489 	AppendBufL( aBuf,iSourceUri );
       
   490 	AppendBufL(aBuf,iInstallNotify);
       
   491 	AppendBufL( aBuf,iUpdatedDDUri );	
       
   492 	APPEND_BUF_INT( aBuf, mediaCount );	
       
   493 	}
       
   494 
       
   495 // ---------------------------------------------------------
       
   496 // CCodData::LoadStorageInfoL()
       
   497 // ---------------------------------------------------------
       
   498 //
       
   499 void CCodData::LoadStorageInfoL(RFile& aInFile)
       
   500 	{
       
   501 	TInt mediaCount(0);
       
   502     ReadHBufCL( aInFile,iName );
       
   503     ReadHBufCL( aInFile,iVendor );
       
   504     ReadHBufCL( aInFile,iNextUrl );
       
   505     READ_INT_L( aInFile,iSize );
       
   506     ReadHBufCL( aInFile,iPrice );
       
   507 	ReadHBufCL( aInFile,iSourceUri );
       
   508 	ReadHBufCL(aInFile,iInstallNotify);
       
   509 	ReadHBufCL( aInFile,iUpdatedDDUri );
       
   510 	READ_INT_L( aInFile, mediaCount );
       
   511 	
       
   512 	for( TInt i = 0; i < mediaCount; ++i )
       
   513 	    {
       
   514         CMediaObjectData *mediaObject = CMediaObjectData::NewL();
       
   515     	AppendMediaObjectL( mediaObject );
       
   516 	    }
       
   517 	}
       
   518 	
       
   519 // ---------------------------------------------------------
       
   520 // CCodData::AppendMediaObjectL()
       
   521 // ---------------------------------------------------------
       
   522 //
       
   523 
       
   524 TInt CCodData::AppendMediaObjectL( CMediaObjectData *aMO )
       
   525     {
       
   526     //Check if the same media object has already been added to the array.
       
   527     //Return index if index is present
       
   528     TInt i;
       
   529 
       
   530     for( i = 0; i < iMediaObjects.Count(); ++i )
       
   531         {
       
   532         if( iMediaObjects[i] == aMO )
       
   533             {
       
   534             return i;
       
   535             }
       
   536         }
       
   537 
       
   538     iMediaObjects.AppendL( aMO );
       
   539     iSize += aMO->Size();
       
   540     // return item index
       
   541     return iMediaObjects.Count();    
       
   542     }
       
   543     
       
   544 // ---------------------------------------------------------
       
   545 // CCodData::operator[]
       
   546 // ---------------------------------------------------------
       
   547 //
       
   548 
       
   549 EXPORT_C CMediaObjectData *CCodData::operator[]( TInt aIndex )
       
   550     {
       
   551     //Check if the media object exits at specified index. Return the same if it is.
       
   552     if( aIndex > 0 && aIndex <= iMediaObjects.Count() )
       
   553         {
       
   554         return iMediaObjects[aIndex-1];
       
   555         }
       
   556     return NULL;    
       
   557     }
       
   558 
       
   559 // ---------------------------------------------------------
       
   560 // CCodData::operator[]
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 
       
   564 EXPORT_C CMediaObjectData *CCodData::operator[]( TInt aIndex ) const
       
   565     {
       
   566     //Check if the media object exits at specified index. Return the same if it is.
       
   567     if( aIndex > 0 && aIndex <= iMediaObjects.Count() )
       
   568         {
       
   569         return iMediaObjects[aIndex-1];
       
   570         }
       
   571     return NULL;    
       
   572     }
       
   573     
       
   574 // ---------------------------------------------------------
       
   575 // CCodData::ActiveDownload
       
   576 // ---------------------------------------------------------
       
   577 //        
       
   578 EXPORT_C TInt CCodData::ActiveDownload() const
       
   579 	{
       
   580 	return iActiveDownload;    
       
   581 	}