photosgallery/viewframework/drmutility/src/glxdrmutility.cpp
branchRCL_3
changeset 9 6b87b143d312
parent 0 4e91876724a2
child 14 ce1c7ad1f18b
equal deleted inserted replaced
5:f7f0874bfe7d 9:6b87b143d312
    33 
    33 
    34 #include <caf/caf.h>
    34 #include <caf/caf.h>
    35 #include <caf/content.h>
    35 #include <caf/content.h>
    36 #include <caf/data.h>
    36 #include <caf/data.h>
    37 #include <caf/manager.h>
    37 #include <caf/manager.h>
       
    38 #include "glxtracer.h"
    38 
    39 
    39 const TInt KGlxDRMThumbnailHeight = 120;
    40 const TInt KGlxDRMThumbnailHeight = 120;
    40 const TInt KGlxDRMThumbnailWidth = 90;
    41 const TInt KGlxDRMThumbnailWidth = 90;
    41 
    42 
    42 // ======== MEMBER FUNCTIONS ========
    43 // ======== MEMBER FUNCTIONS ========
    62 //============================================================================
    63 //============================================================================
    63 // InstanceL
    64 // InstanceL
    64 //============================================================================
    65 //============================================================================
    65 EXPORT_C CGlxDRMUtility* CGlxDRMUtility::InstanceL()
    66 EXPORT_C CGlxDRMUtility* CGlxDRMUtility::InstanceL()
    66     {
    67     {
       
    68     TRACER("CGlxDRMUtility::InstanceL()");
    67     CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls());
    69     CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls());
    68     
    70     
    69     if(tls==NULL)
    71     if ( !tls )
    70         {
    72         {
    71         CGlxDRMUtility* drmutil = new(ELeave)CGlxDRMUtility();
    73         CGlxDRMUtility* drmutil = new(ELeave)CGlxDRMUtility();
    72         CleanupStack::PushL(drmutil);
    74         CleanupStack::PushL(drmutil);
    73         drmutil->ConstructL();
    75         drmutil->ConstructL();
    74         
    76         
    87 //============================================================================
    89 //============================================================================
    88 // Close
    90 // Close
    89 //============================================================================ 
    91 //============================================================================ 
    90 EXPORT_C void CGlxDRMUtility::Close()
    92 EXPORT_C void CGlxDRMUtility::Close()
    91     {
    93     {
       
    94     TRACER("CGlxDRMUtility::Close()");
    92     CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls());
    95     CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls());
    93    
    96    
    94     if (tls != NULL) 
    97     if ( tls ) 
    95         {
    98         {
    96         tls->iRefCount--;
    99         tls->iRefCount--;
    97         
   100         
    98         // Delete the tls pointer and list manager instance if this was the 
   101         // Delete the tls pointer and list manager instance if this was the 
    99         // last reference
   102         // last reference
   109 //============================================================================
   112 //============================================================================
   110 // Destructor
   113 // Destructor
   111 //============================================================================ 
   114 //============================================================================ 
   112 CGlxDRMUtility::~CGlxDRMUtility()
   115 CGlxDRMUtility::~CGlxDRMUtility()
   113     {
   116     {
       
   117     TRACER("CGlxDRMUtility::~CGlxDRMUtility()");
   114     delete iCManager;
   118     delete iCManager;
   115     delete iDrmHelper;
   119     delete iDrmHelper;
   116     delete iLastConsumedItemUri;
   120     delete iLastConsumedItemUri;
   117     }
   121     }
   118     
   122     
   120 // CheckOpenRightsL
   124 // CheckOpenRightsL
   121 //============================================================================ 
   125 //============================================================================ 
   122 EXPORT_C TBool CGlxDRMUtility::CheckOpenRightsL( const TDesC& aUri, 
   126 EXPORT_C TBool CGlxDRMUtility::CheckOpenRightsL( const TDesC& aUri, 
   123                                                 TBool aCheckViewRights )
   127                                                 TBool aCheckViewRights )
   124     {
   128     {
       
   129     TRACER("CGlxDRMUtility::CheckOpenRightsL()");
   125     // When checking current rights for a URI, clear stored URI
   130     // When checking current rights for a URI, clear stored URI
   126     TPtr ptr = iLastConsumedItemUri->Des();
   131     TPtr ptr = iLastConsumedItemUri->Des();
   127     ptr.Zero();
   132     ptr.Zero();
   128     iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL( 0 );
   133     iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL( 0 );
   129 
   134 
   143 // CheckDisplayRightsL
   148 // CheckDisplayRightsL
   144 //============================================================================ 
   149 //============================================================================ 
   145 EXPORT_C TBool CGlxDRMUtility::CheckDisplayRightsL( const TDesC& aUri, 
   150 EXPORT_C TBool CGlxDRMUtility::CheckDisplayRightsL( const TDesC& aUri, 
   146                                                     TBool aCheckViewRights )
   151                                                     TBool aCheckViewRights )
   147     {
   152     {
       
   153     TRACER("CGlxDRMUtility::CheckDisplayRightsL()");
   148     // Allow to display if rights for a URI was just consumed (i.e. same as stored URI)
   154     // Allow to display if rights for a URI was just consumed (i.e. same as stored URI)
   149     if ( iLastConsumedItemUri->Length() > 0 )
   155     if ( iLastConsumedItemUri->Length() > 0 )
   150         {
   156         {
   151         if ( aUri.CompareF( *iLastConsumedItemUri ) == 0 )
   157         if ( aUri.CompareF( *iLastConsumedItemUri ) == 0 )
   152             {
   158             {
   161 //============================================================================
   167 //============================================================================
   162 // ConsumeRightsL
   168 // ConsumeRightsL
   163 //============================================================================    
   169 //============================================================================    
   164 EXPORT_C TBool CGlxDRMUtility::ConsumeRightsL(const TDesC& aUri)
   170 EXPORT_C TBool CGlxDRMUtility::ConsumeRightsL(const TDesC& aUri)
   165     {
   171     {
       
   172     TRACER("CGlxDRMUtility::ConsumeRightsL()");
   166     TVirtualPathPtr path( aUri, KDefaultContentObject() );
   173     TVirtualPathPtr path( aUri, KDefaultContentObject() );
   167 
   174 
   168     // Create a CData object to read the content
   175     // Create a CData object to read the content
   169     // Tell the agent we are planning to display the content
   176     // Tell the agent we are planning to display the content
   170     CData* data = CData::NewLC(path, ContentAccess::EView, EContentShareReadOnly);
   177     CData* data = CData::NewLC(path, ContentAccess::EView, EContentShareReadOnly);
   193 // Test whether a media item is OMA DRM 2.0 protected and has an associated
   200 // Test whether a media item is OMA DRM 2.0 protected and has an associated
   194 // info URL.
   201 // info URL.
   195 //============================================================================
   202 //============================================================================
   196 EXPORT_C TBool CGlxDRMUtility::CanShowInfoOnlineL(TDesC& aUri)
   203 EXPORT_C TBool CGlxDRMUtility::CanShowInfoOnlineL(TDesC& aUri)
   197     {
   204     {
       
   205     TRACER("CGlxDRMUtility::CanShowInfoOnlineL()");
   198     TBool canShowInfoOnline = EFalse;
   206     TBool canShowInfoOnline = EFalse;
   199 
   207 
   200     HBufC8* urlBuf = NULL;
   208     HBufC8* urlBuf = NULL;
   201     canShowInfoOnline = iDrmHelper->HasInfoUrlL(aUri, urlBuf);
   209     canShowInfoOnline = iDrmHelper->HasInfoUrlL(aUri, urlBuf);
   202 
   210 
   209 //============================================================================
   217 //============================================================================
   210 // Open the associated info URL for a media item in the browser.
   218 // Open the associated info URL for a media item in the browser.
   211 //============================================================================
   219 //============================================================================
   212 EXPORT_C void CGlxDRMUtility::ShowInfoOnlineL(TDesC& aUri)
   220 EXPORT_C void CGlxDRMUtility::ShowInfoOnlineL(TDesC& aUri)
   213     {
   221     {
       
   222     TRACER("CGlxDRMUtility::ShowInfoOnlineL()");
   214     iDrmHelper->OpenInfoUrlL(aUri);
   223     iDrmHelper->OpenInfoUrlL(aUri);
   215     }
   224     }
   216 
   225 
   217 //============================================================================
   226 //============================================================================
   218 // Test whether a media item can be set as automated content.
   227 // Test whether a media item can be set as automated content.
   219 //============================================================================
   228 //============================================================================
   220 EXPORT_C TBool CGlxDRMUtility::CanSetAsAutomatedL(const TDesC& aUri, 
   229 EXPORT_C TBool CGlxDRMUtility::CanSetAsAutomatedL(const TDesC& aUri, 
   221                                     TGlxDrmAutomatedType aType)
   230                                     TGlxDrmAutomatedType aType)
   222     {
   231     {
       
   232     TRACER("CGlxDRMUtility::CanSetAsAutomatedL()");
   223     TBool canSetAutomated = EFalse;
   233     TBool canSetAutomated = EFalse;
   224     switch(aType)
   234     switch(aType)
   225         {
   235         {
   226     case EGlxDrmAutomatedTypeWallpaper:
   236     case EGlxDrmAutomatedTypeWallpaper:
   227         {
   237         {
   239 // SetAsAutomatedL
   249 // SetAsAutomatedL
   240 //============================================================================
   250 //============================================================================
   241 EXPORT_C void CGlxDRMUtility::SetAsAutomatedL(const TDesC& aUri, 
   251 EXPORT_C void CGlxDRMUtility::SetAsAutomatedL(const TDesC& aUri, 
   242                                     TGlxDrmAutomatedType aType)
   252                                     TGlxDrmAutomatedType aType)
   243     {
   253     {
       
   254     TRACER("CGlxDRMUtility::SetAsAutomatedL()");
   244      switch(aType)
   255      switch(aType)
   245         {
   256         {
   246     case EGlxDrmAutomatedTypeWallpaper:
   257     case EGlxDrmAutomatedTypeWallpaper:
   247         {
   258         {
   248         TInt error = iDrmHelper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper);
   259         TInt error = iDrmHelper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper);
   265 //============================================================================
   276 //============================================================================
   266 // ShowDRMDetailsPane
   277 // ShowDRMDetailsPane
   267 //============================================================================  
   278 //============================================================================  
   268 EXPORT_C void CGlxDRMUtility::ShowDRMDetailsPaneL( const TDesC& aUri )
   279 EXPORT_C void CGlxDRMUtility::ShowDRMDetailsPaneL( const TDesC& aUri )
   269     {
   280     {
       
   281     TRACER("CGlxDRMUtility::ShowDRMDetailsPaneL()");
   270     TRAPD( err, iDrmHelper->LaunchDetailsViewEmbeddedL( aUri ) );
   282     TRAPD( err, iDrmHelper->LaunchDetailsViewEmbeddedL( aUri ) );
   271     // if no rights ask user to re-activate?
   283     // if no rights ask user to re-activate?
   272     if( err == KErrCANoRights )
   284     if( err == KErrCANoRights )
   273         {
   285         {
   274         HBufC* buf = aUri.AllocLC();
   286         HBufC* buf = aUri.AllocLC();
   281 //============================================================================
   293 //============================================================================
   282 // IsForwardLockedL
   294 // IsForwardLockedL
   283 //============================================================================  
   295 //============================================================================  
   284 EXPORT_C TBool CGlxDRMUtility::IsForwardLockedL(const TDesC& aUri)
   296 EXPORT_C TBool CGlxDRMUtility::IsForwardLockedL(const TDesC& aUri)
   285     {
   297     {
       
   298     TRACER("CGlxDRMUtility::IsForwardLockedL()");
   286     TBool forwardLocked = EFalse;
   299     TBool forwardLocked = EFalse;
   287     TVirtualPathPtr path( aUri, KDefaultContentObject() );
   300     TVirtualPathPtr path( aUri, KDefaultContentObject() );
   288 
   301 
   289     // forwardLocked is not updated if an error occurs
   302     // forwardLocked is not updated if an error occurs
   290     iCManager->GetAttribute( ContentAccess::EIsForwardable, forwardLocked, path );
   303     iCManager->GetAttribute( ContentAccess::EIsForwardable, forwardLocked, path );
   295 //============================================================================
   308 //============================================================================
   296 // ShowRightsInfoL
   309 // ShowRightsInfoL
   297 //============================================================================    
   310 //============================================================================    
   298 EXPORT_C void CGlxDRMUtility::ShowRightsInfoL(const TDesC& aUri)    
   311 EXPORT_C void CGlxDRMUtility::ShowRightsInfoL(const TDesC& aUri)    
   299     {
   312     {
       
   313     TRACER("CGlxDRMUtility::ShowRightsInfoL()");
   300     iDrmHelper->CheckRightsAmountL( aUri );
   314     iDrmHelper->CheckRightsAmountL( aUri );
   301     }
   315     }
   302 
   316 
   303 //============================================================================
   317 //============================================================================
   304 // Return size for DRM thumbnail request.
   318 // Return size for DRM thumbnail request.
   305 //============================================================================
   319 //============================================================================
   306 EXPORT_C TSize CGlxDRMUtility::DRMThumbnailSize(TSize& aSize)
   320 EXPORT_C TSize CGlxDRMUtility::DRMThumbnailSize(TSize& aSize)
   307     {
   321     {
       
   322     TRACER("CGlxDRMUtility::DRMThumbnailSize()");
   308     TSize thumbnailSize(KGlxDRMThumbnailWidth, KGlxDRMThumbnailHeight);
   323     TSize thumbnailSize(KGlxDRMThumbnailWidth, KGlxDRMThumbnailHeight);
   309     
   324     
   310     if((aSize.iWidth*aSize.iHeight)/4 < 
   325     if((aSize.iWidth*aSize.iHeight)/4 < 
   311             KGlxDRMThumbnailWidth * KGlxDRMThumbnailHeight)
   326             KGlxDRMThumbnailWidth * KGlxDRMThumbnailHeight)
   312         {
   327         {
   320 /**
   335 /**
   321  * C++ default constructor.
   336  * C++ default constructor.
   322  */
   337  */
   323 CGlxDRMUtility::CGlxDRMUtility()
   338 CGlxDRMUtility::CGlxDRMUtility()
   324     {
   339     {
   325     
   340     TRACER("CGlxDRMUtility::CGlxDRMUtility()");
   326     }
   341     }
   327 
   342 
   328 /**
   343 /**
   329  * By default Symbian 2nd phase constructor is private.
   344  * By default Symbian 2nd phase constructor is private.
   330  */
   345  */
   331 void CGlxDRMUtility::ConstructL()
   346 void CGlxDRMUtility::ConstructL()
   332     {
   347     {
       
   348     TRACER("CGlxDRMUtility::ConstructL()");
   333     iCManager = ContentAccess::CManager::NewL();
   349     iCManager = ContentAccess::CManager::NewL();
   334     iDrmHelper = CDRMHelper::NewL();
   350     iDrmHelper = CDRMHelper::NewL();
   335     iLastConsumedItemUri = HBufC::NewL(0);
   351     iLastConsumedItemUri = HBufC::NewL(0);
   336     }
   352     }
   337 
   353