ncdengine/provider/src/ncdpurchasedownloadinfo.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of CNcdPurchaseDownloadInfo
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 
       
    21 #include "ncdutils.h"
       
    22 #include "catalogsutils.h"
       
    23 #include "ncdattributes.h"
       
    24 
       
    25 EXPORT_C CNcdPurchaseDownloadInfo* CNcdPurchaseDownloadInfo::NewL()
       
    26     {
       
    27     CNcdPurchaseDownloadInfo* self = NewLC();
       
    28     CleanupStack::Pop( self );
       
    29     return self;
       
    30     }
       
    31 
       
    32 EXPORT_C CNcdPurchaseDownloadInfo* CNcdPurchaseDownloadInfo::NewLC()
       
    33     {
       
    34     CNcdPurchaseDownloadInfo* self = new (ELeave) CNcdPurchaseDownloadInfo;
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     return self;
       
    38     }
       
    39 
       
    40 EXPORT_C CNcdPurchaseDownloadInfo* CNcdPurchaseDownloadInfo::NewL(
       
    41     const MNcdPurchaseDownloadInfo& aSource )
       
    42     {
       
    43     CNcdPurchaseDownloadInfo* self = NewLC( aSource );
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 EXPORT_C CNcdPurchaseDownloadInfo* CNcdPurchaseDownloadInfo::NewLC(
       
    49     const MNcdPurchaseDownloadInfo& aSource )
       
    50     {
       
    51     CNcdPurchaseDownloadInfo* self = new (ELeave) CNcdPurchaseDownloadInfo;
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL( aSource );
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 EXPORT_C CNcdPurchaseDownloadInfo::CNcdPurchaseDownloadInfo()
       
    59 : CBase()
       
    60     {
       
    61     }
       
    62 
       
    63 
       
    64 EXPORT_C void CNcdPurchaseDownloadInfo::ConstructL()
       
    65     {
       
    66     SetContentUsage( MNcdPurchaseDownloadInfo::EDownloadable );
       
    67     SetContentUriL( KNullDesC );
       
    68     SetContentValidityDelta( -1 );
       
    69     SetContentMimeTypeL( KNullDesC );
       
    70     SetContentSize( 0 );
       
    71     SetLaunchable( EFalse );
       
    72     SetDescriptorTypeL( KNullDesC );
       
    73     SetDescriptorNameL( KNullDesC );
       
    74     SetDescriptorUriL( KNullDesC );
       
    75     SetDescriptorDataL( KNullDesC8 );
       
    76     SetRightsUriL( KNullDesC );
       
    77     SetRightsTypeL( KNullDesC );
       
    78     SetActivationKeyL( KNullDesC );
       
    79     SetInstallNotificationUriL( KNullDesC );
       
    80     }
       
    81 
       
    82 EXPORT_C void CNcdPurchaseDownloadInfo::ConstructL(
       
    83     const MNcdPurchaseDownloadInfo& aSource )
       
    84     {
       
    85     SetContentUsage( aSource.ContentUsage() );
       
    86     SetContentUriL( aSource.ContentUri() );
       
    87     SetContentValidityDelta( aSource.ContentValidityDelta() );
       
    88     SetContentMimeTypeL( aSource.ContentMimeType() );
       
    89     SetContentSize( aSource.ContentSize() );
       
    90     SetLaunchable( aSource.IsLaunchable() );
       
    91     SetDescriptorTypeL( aSource.DescriptorType() );
       
    92     SetDescriptorNameL( aSource.DescriptorName() );
       
    93     SetDescriptorUriL( aSource.DescriptorUri() );
       
    94     SetDescriptorDataL( aSource.DescriptorData() );
       
    95     SetRightsUriL( aSource.RightsUri() );
       
    96     SetRightsTypeL( aSource.RightsType() );
       
    97     SetActivationKeyL( aSource.ActivationKey() );
       
    98     SetInstallNotificationUriL( aSource.InstallNotificationUri() );
       
    99     
       
   100     // Some ugly stuff for copying the attributes
       
   101     // This WILL NOT work for other MNcdPurchaseDownloadInfo-implementations
       
   102     // if there's going to be any
       
   103     const CNcdPurchaseDownloadInfo& info = 
       
   104         static_cast<const CNcdPurchaseDownloadInfo&>( aSource );
       
   105     
       
   106     if ( info.iAttributes ) 
       
   107         {
       
   108         iAttributes = CNcdAttributes::NewL( *info.iAttributes );
       
   109         }
       
   110     }
       
   111 
       
   112             
       
   113 EXPORT_C CNcdPurchaseDownloadInfo::~CNcdPurchaseDownloadInfo()
       
   114     {
       
   115     delete iContentUri;
       
   116     delete iContentMimeType;
       
   117     delete iDescriptorType;
       
   118     delete iDescriptorName;
       
   119     delete iDescriptorUri;
       
   120     delete iDescriptorData;
       
   121     delete iRightsUri;
       
   122     delete iRightsType;
       
   123     delete iActivationKey;
       
   124     delete iInstallNotificationUri;
       
   125     delete iAttributes;
       
   126     }
       
   127 
       
   128 
       
   129 EXPORT_C MNcdPurchaseDownloadInfo::TContentUsage
       
   130     CNcdPurchaseDownloadInfo::ContentUsage() const
       
   131     {
       
   132     return iContentUsage;
       
   133     }
       
   134 
       
   135 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::ContentUri() const
       
   136     {
       
   137     return *iContentUri;
       
   138     }
       
   139 
       
   140 EXPORT_C TInt CNcdPurchaseDownloadInfo::ContentValidityDelta() const
       
   141     {
       
   142     return iValidityDelta;
       
   143     }
       
   144 
       
   145 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::ContentMimeType() const
       
   146     {
       
   147     return *iContentMimeType;
       
   148     }
       
   149 
       
   150 EXPORT_C TInt CNcdPurchaseDownloadInfo::ContentSize() const
       
   151     {
       
   152     return iContentSize;
       
   153     }
       
   154 
       
   155 EXPORT_C TBool CNcdPurchaseDownloadInfo::IsLaunchable() const
       
   156     {
       
   157     return iLaunchable;
       
   158     }
       
   159 
       
   160 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::DescriptorType() const
       
   161     {
       
   162     return *iDescriptorType;
       
   163     }
       
   164 
       
   165 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::DescriptorName() const
       
   166     {
       
   167     return *iDescriptorName;
       
   168     }
       
   169 
       
   170 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::DescriptorUri() const
       
   171     {
       
   172     return *iDescriptorUri;
       
   173     }
       
   174 
       
   175 EXPORT_C const TDesC8& CNcdPurchaseDownloadInfo::DescriptorData() const
       
   176     {
       
   177     return *iDescriptorData;
       
   178     }
       
   179 
       
   180 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::RightsUri() const
       
   181     {
       
   182     return *iRightsUri;
       
   183     }
       
   184 
       
   185 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::RightsType() const
       
   186     {
       
   187     return *iRightsType;
       
   188     }
       
   189 
       
   190 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::ActivationKey() const
       
   191     {
       
   192     return *iActivationKey;
       
   193     }
       
   194     
       
   195 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::InstallNotificationUri() const
       
   196     {
       
   197     return *iInstallNotificationUri;
       
   198     }
       
   199     
       
   200     
       
   201 EXPORT_C const TDesC& CNcdPurchaseDownloadInfo::AttributeStringL( 
       
   202     TDownloadAttribute aAttribute ) const
       
   203     {
       
   204     DLTRACEIN((""));
       
   205     if ( !iAttributes || 
       
   206          iAttributes->AttributeType( aAttribute ) == 
       
   207             CNcdAttributes::EAttributeTypeUndefined )
       
   208         {
       
   209         DLERROR(("Attribute not set yet"));
       
   210         User::Leave( KErrNotFound );
       
   211         }
       
   212     return iAttributes->AttributeString16( aAttribute );    
       
   213     }
       
   214 
       
   215 
       
   216 EXPORT_C TInt32 CNcdPurchaseDownloadInfo::AttributeInt32L( 
       
   217     TDownloadAttribute aAttribute ) const
       
   218     {
       
   219     if ( !iAttributes || 
       
   220          iAttributes->AttributeType( aAttribute ) == 
       
   221             CNcdAttributes::EAttributeTypeUndefined )
       
   222         {
       
   223         User::Leave( KErrNotFound );
       
   224         }
       
   225     return iAttributes->AttributeInt32( aAttribute );    
       
   226     }
       
   227     
       
   228 
       
   229 EXPORT_C void CNcdPurchaseDownloadInfo::ExternalizeL( RWriteStream& aStream ) const
       
   230     {
       
   231     aStream.WriteInt16L( iContentUsage );
       
   232     ExternalizeDesL( *iContentUri, aStream );
       
   233     aStream.WriteInt32L( iValidityDelta );
       
   234     ExternalizeDesL( *iContentMimeType, aStream );
       
   235     aStream.WriteInt32L( iContentSize );
       
   236     aStream.WriteInt8L( iLaunchable );
       
   237     ExternalizeDesL( *iDescriptorType, aStream );
       
   238     ExternalizeDesL( *iDescriptorName, aStream );
       
   239     ExternalizeDesL( *iDescriptorUri, aStream );
       
   240     ExternalizeDesL( *iDescriptorData, aStream );
       
   241     ExternalizeDesL( *iRightsUri, aStream );
       
   242     ExternalizeDesL( *iRightsType, aStream );
       
   243     ExternalizeDesL( *iActivationKey, aStream );
       
   244     ExternalizeDesL( *iInstallNotificationUri, aStream );
       
   245     
       
   246     if ( iAttributes ) 
       
   247         {
       
   248         aStream.WriteInt8L( 1 );
       
   249         iAttributes->ExternalizeL( aStream );
       
   250         }
       
   251     else 
       
   252         {
       
   253         aStream.WriteInt8L( 0 );
       
   254         }
       
   255     }
       
   256 
       
   257 EXPORT_C void CNcdPurchaseDownloadInfo::InternalizeL( RReadStream& aStream )
       
   258     {
       
   259     iContentUsage = (TContentUsage)aStream.ReadInt16L();
       
   260     InternalizeDesL( iContentUri, aStream );
       
   261     iValidityDelta = aStream.ReadInt32L();
       
   262     InternalizeDesL( iContentMimeType, aStream );
       
   263     iContentSize = aStream.ReadInt32L();
       
   264     iLaunchable = aStream.ReadInt8L();
       
   265     InternalizeDesL( iDescriptorType, aStream );
       
   266     InternalizeDesL( iDescriptorName, aStream );
       
   267     InternalizeDesL( iDescriptorUri, aStream );
       
   268     InternalizeDesL( iDescriptorData, aStream );
       
   269     InternalizeDesL( iRightsUri, aStream );
       
   270     InternalizeDesL( iRightsType, aStream );
       
   271     InternalizeDesL( iActivationKey, aStream );
       
   272     InternalizeDesL( iInstallNotificationUri, aStream );
       
   273     
       
   274     delete iAttributes;
       
   275     iAttributes = NULL;
       
   276     
       
   277     TInt8 attribsExist = aStream.ReadInt8L();
       
   278     if ( attribsExist ) 
       
   279         {
       
   280         
       
   281         iAttributes = CNcdAttributes::NewL( 
       
   282             aStream,
       
   283             MNcdPurchaseDownloadInfo::EDownloadAttributeInternal );
       
   284         }
       
   285     }
       
   286 
       
   287 EXPORT_C void CNcdPurchaseDownloadInfo::SetContentUsage(
       
   288     TContentUsage aUsage )
       
   289     {
       
   290     DLTRACEIN(("Content usage: %d", aUsage));
       
   291     iContentUsage = aUsage;
       
   292     }
       
   293 
       
   294 EXPORT_C void CNcdPurchaseDownloadInfo::SetContentUriL( const TDesC& aUri )
       
   295     {
       
   296     DLTRACEIN(( _L("URI: %S"), &aUri ));
       
   297     AssignDesL( iContentUri, aUri );
       
   298     }
       
   299 
       
   300 EXPORT_C void CNcdPurchaseDownloadInfo::SetContentValidityDelta(
       
   301     TInt aValidityDelta )
       
   302     {
       
   303     iValidityDelta = aValidityDelta;
       
   304     }
       
   305 
       
   306 EXPORT_C void CNcdPurchaseDownloadInfo::SetContentMimeTypeL(
       
   307     const TDesC& aMimeType )
       
   308     {
       
   309     DLTRACEIN(( _L("Mime: %S"), &aMimeType ));
       
   310     AssignDesL( iContentMimeType, aMimeType );
       
   311     }
       
   312 
       
   313 EXPORT_C void CNcdPurchaseDownloadInfo::SetContentSize( TInt aSize )
       
   314     {
       
   315     iContentSize = aSize;
       
   316     }
       
   317 
       
   318 EXPORT_C void CNcdPurchaseDownloadInfo::SetLaunchable( TBool aLaunchable )
       
   319     {
       
   320     DLTRACEIN(("Launchable: %d", aLaunchable));
       
   321     iLaunchable = aLaunchable;
       
   322     }
       
   323 
       
   324 EXPORT_C void CNcdPurchaseDownloadInfo::SetDescriptorTypeL(
       
   325     const TDesC& aType )
       
   326     {
       
   327     DLTRACEIN(( _L("Descriptor type: %S"), &aType ));
       
   328     AssignDesL( iDescriptorType, aType );
       
   329     }
       
   330 
       
   331 EXPORT_C void CNcdPurchaseDownloadInfo::SetDescriptorNameL(
       
   332     const TDesC& aName )
       
   333     {
       
   334     DLTRACEIN(( _L("Descriptor name: %S"), &aName ));
       
   335     AssignDesL( iDescriptorName, aName );
       
   336     }
       
   337 
       
   338 EXPORT_C void CNcdPurchaseDownloadInfo::SetDescriptorUriL( const TDesC& aUri )
       
   339     {
       
   340     DLTRACEIN(( _L("Descriptor URI: %S"), &aUri ));
       
   341     AssignDesL( iDescriptorUri, aUri );
       
   342     }
       
   343 
       
   344 EXPORT_C void CNcdPurchaseDownloadInfo::SetDescriptorDataL(
       
   345     const TDesC8& aData )
       
   346     {    
       
   347     AssignDesL( iDescriptorData, aData );
       
   348     }
       
   349 
       
   350 EXPORT_C void CNcdPurchaseDownloadInfo::SetRightsUriL( const TDesC& aUri )
       
   351     {
       
   352     AssignDesL( iRightsUri, aUri );
       
   353     }
       
   354 
       
   355 EXPORT_C void CNcdPurchaseDownloadInfo::SetRightsTypeL( const TDesC& aType )
       
   356     {
       
   357     DLTRACEIN(( _L("Rights type: %S"), &aType ));
       
   358     AssignDesL( iRightsType, aType );
       
   359     }
       
   360 
       
   361 EXPORT_C void CNcdPurchaseDownloadInfo::SetActivationKeyL(
       
   362     const TDesC& aActivationKey )
       
   363     {
       
   364     AssignDesL( iActivationKey, aActivationKey );
       
   365     }
       
   366 
       
   367 EXPORT_C void CNcdPurchaseDownloadInfo::SetInstallNotificationUriL(
       
   368     const TDesC& aInstallNotificationUri )
       
   369     {
       
   370     AssignDesL( iInstallNotificationUri, aInstallNotificationUri );
       
   371     }
       
   372 
       
   373 
       
   374 EXPORT_C void CNcdPurchaseDownloadInfo::SetAttributeL( 
       
   375     TDownloadAttribute aAttribute, TInt32 aValue )
       
   376     {
       
   377     CreateAttributesL();
       
   378     iAttributes->SetAttributeL( aAttribute, aValue );
       
   379     }
       
   380 
       
   381 EXPORT_C void CNcdPurchaseDownloadInfo::SetAttributeL( 
       
   382     TDownloadAttribute aAttribute, const TDesC& aValue )
       
   383     {
       
   384     CreateAttributesL();
       
   385     iAttributes->SetAttributeL( aAttribute, aValue );
       
   386     }
       
   387 
       
   388 EXPORT_C void CNcdPurchaseDownloadInfo::CreateAttributesL()
       
   389     {
       
   390     DLTRACEIN((""));
       
   391     if ( !iAttributes ) 
       
   392         {
       
   393         iAttributes = CNcdAttributes::NewL( 
       
   394             MNcdPurchaseDownloadInfo::EDownloadAttributeInternal );
       
   395         }
       
   396     }