profilesservices/ProfileEngine/WrapperSrc/CProEngToneHandlerDrmFull.cpp
changeset 0 8c5d936e5675
child 25 3b47783fdf16
child 29 56ba5cd39aab
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     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 "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 the CProEngToneHandler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProEngToneHandler.h"
       
    22 
       
    23 #include    <DRMHelper.h>
       
    24 #include    <DRMCommon.h>
       
    25 #include    <ProEngWrapper.rsg>
       
    26 
       
    27 #include <caf/caf.h>
       
    28 
       
    29 
       
    30 // ============================ LOCAL FUNCTIONS ================================
       
    31 
       
    32 CDRMHelper::TDRMHelperAutomatedType SettingIdToAutomatedType( TProfileSettingId aSettingId )
       
    33     {
       
    34     switch( aSettingId )
       
    35         {
       
    36         case EProfileSettingIdRingingTone:
       
    37         case EProfileSettingIdRingingTone2:
       
    38             {
       
    39             return CDRMHelper::EAutomatedTypeRingingTone;
       
    40             }
       
    41         case EProfileSettingIdMsgTone:
       
    42             {
       
    43             return CDRMHelper::EAutomatedTypeMessageAlert;
       
    44             }
       
    45         case EProfileSettingIdEmailTone:
       
    46             {
       
    47             return CDRMHelper::EAutomatedTypeEmailAlert;
       
    48             }
       
    49         default:
       
    50             {
       
    51             return CDRMHelper::EAutomatedTypeOther;
       
    52             }
       
    53         }
       
    54     }
       
    55 
       
    56 // ============================ MEMBER FUNCTIONS ===============================
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CProEngToneHandler::DrmConstructL
       
    60 // 2nd phase construct for DRM objects
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CProEngToneHandler::DrmConstructL()
       
    64     {
       
    65     iDrmCommon = DRMCommon::NewL();
       
    66     iDrmHelper = CDRMHelper::NewL();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CProEngToneHandler::ReleaseDrm
       
    71 // Destructor for DRM objects
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CProEngToneHandler::ReleaseDrm()
       
    75     {
       
    76     delete iDrmHelper;
       
    77     iDrmHelper = NULL;
       
    78     delete iDrmCommon;
       
    79     iDrmCommon = NULL;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CProEngToneHandler::CheckProtectedFileL
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 TInt CProEngToneHandler::CheckProtectedFileL( const TDesC& aFileName )
       
    87     {
       
    88     DRMCommon::TContentProtection protection;
       
    89     HBufC8* mimeType = NULL; // ignored
       
    90     HBufC8* contentUri = NULL;
       
    91     TUint dataLength; // ignored
       
    92     TInt err = iDrmCommon->GetFileInfo( aFileName, protection, mimeType,
       
    93                                         contentUri, dataLength );
       
    94     delete mimeType;
       
    95     if( err )
       
    96         {
       
    97         delete contentUri;
       
    98         User::Leave( err );
       
    99         }
       
   100     CleanupStack::PushL( contentUri );
       
   101 
       
   102     TInt result( KErrGeneral );
       
   103     CDRMRights* rights = NULL;
       
   104     err = iDrmCommon->GetActiveRights( *contentUri, DRMCommon::EPlay, rights );
       
   105 
       
   106     CleanupStack::PopAndDestroy( contentUri );
       
   107 
       
   108     if( rights == NULL )
       
   109         {
       
   110         if( err == DRMCommon::ENoRights )
       
   111             {
       
   112             // Handle "No rights" situation here
       
   113             iDrmHelper->HandleErrorL( DRMCommon::ENoRights, aFileName );
       
   114             return result;
       
   115             }
       
   116         else
       
   117             {
       
   118             User::Leave( KErrGeneral );
       
   119             }
       
   120         }
       
   121 
       
   122     CleanupStack::PushL( rights );
       
   123     
       
   124 	switch ( err )
       
   125 		{
       
   126 		case CDRMRights::EFullRights: // Fall through
       
   127 		case CDRMRights::ERestrictedRights:
       
   128 			{
       
   129 			CDRMRights::TRestriction restriction; // ignore
       
   130 			CDRMRights::TExpiration expiration;
       
   131 			TUint32 constType;
       
   132 			
       
   133 			rights->GetRightsInfo( DRMCommon::EPlay, restriction, // ignore return
       
   134                                    expiration, constType );       // value
       
   135 		
       
   136             // This is CFM protected file, ringingtone is set to "no"
       
   137             if ( ( rights->GetPermission().iInfoBits & ENoRingingTone )
       
   138                 // This is normal DRM protected count-based tone
       
   139                 || ( constType & CDRMRights::ECountBased ) )
       
   140                     {
       
   141                     ShowErrorNoteL( R_PROENG_TEXT_DRM_PREV_RIGHTS_SET );
       
   142                     }		
       
   143                 else
       
   144                     {
       
   145                     switch ( expiration )
       
   146                         {
       
   147                         case CDRMRights::EValidRights:
       
   148                             {
       
   149                             result = KErrNone;
       
   150                             break;
       
   151                             }
       
   152 
       
   153                         case CDRMRights::EFutureRights:
       
   154                             {
       
   155                             iDrmHelper->HandleErrorL( DRMCommon::ENoRights,
       
   156                                                       aFileName );
       
   157                             break;
       
   158                             }
       
   159 
       
   160                         case CDRMRights::EExpiredRights: 
       
   161                             {
       
   162                             iDrmHelper->HandleErrorL( DRMCommon::ERightsExpired,
       
   163                                                       aFileName );
       
   164                             break;
       
   165                             }
       
   166 
       
   167                         default:
       
   168                             {
       
   169                             break;
       
   170                             }
       
   171                         }	
       
   172 
       
   173                     }
       
   174 				
       
   175 
       
   176 			break;
       
   177 			}
       
   178 
       
   179 		case CDRMRights::EPreviewRights:
       
   180 			{
       
   181 			ShowErrorNoteL( R_PROENG_TEXT_DRM_PREV_RIGHTS_SET );
       
   182 			break;
       
   183 			}
       
   184 
       
   185 		case DRMCommon::ENoRights:
       
   186 			{
       
   187 			iDrmHelper->HandleErrorL( DRMCommon::ENoRights, aFileName );
       
   188 			break;
       
   189 			}
       
   190 
       
   191 		default:
       
   192 			{
       
   193 			break;
       
   194 			}
       
   195 
       
   196 		}
       
   197    
       
   198     CleanupStack::PopAndDestroy( rights );
       
   199 
       
   200 	return result;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CProEngToneHandler::CanSetAutomated
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TBool CProEngToneHandler::CanSetAutomated( const TDesC& aFileName )
       
   208     {
       
   209     TBool canSetAutomated( EFalse );
       
   210     return
       
   211         ( iDrmHelper->CanSetAutomated( aFileName, canSetAutomated ) == KErrNone
       
   212         && canSetAutomated );
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CProEngToneHandler::AskAutomated
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 TInt CProEngToneHandler::AskAutomated( const TDesC& aFileName )
       
   220     {
       
   221     return iDrmHelper->ShowAutomatedNote( aFileName );
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CProEngToneHandler::SetAutomated
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CProEngToneHandler::SetAutomated( TProfileSettingId aSettingId,
       
   229                                        const TDesC& aFileName )
       
   230     {
       
   231     TInt err = KErrNone;
       
   232 
       
   233     TRAP_IGNORE( err = SetAutomatedL( aSettingId, aFileName ) );
       
   234 
       
   235     return err;
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CProEngToneHandler::SetAutomatedL
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt CProEngToneHandler::SetAutomatedL( TProfileSettingId aSettingId,
       
   243                                        const TDesC& aFileName )
       
   244     {
       
   245     iDrmHelper->SetAutomatedType( SettingIdToAutomatedType( aSettingId ) );
       
   246     TInt err( iDrmHelper->SetAutomatedSilent( aFileName, EFalse ) );
       
   247     if( err == KErrNone )
       
   248         {
       
   249         using namespace ContentAccess;
       
   250        	TVirtualPathPtr path( aFileName, KDefaultContentObject );
       
   251         CData* data = CData::NewLC( path, EContentShareReadWrite );
       
   252         err = data->ExecuteIntent( EPlay );
       
   253         CleanupStack::PopAndDestroy( data );
       
   254         // According to Risto Vilkman from DRM, KErrAccessDenied
       
   255         // can be ignored at this point, since if
       
   256         // CanSetAutomated says the tone is OK, it's OK.
       
   257         if( err == KErrAccessDenied )
       
   258         	{
       
   259         	err = KErrNone;
       
   260         	}
       
   261         }
       
   262     return err;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CProEngToneHandler::RemoveAutomated
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CProEngToneHandler::RemoveAutomated( const TDesC& aFileName )
       
   270     {
       
   271     iDrmHelper->RemoveAutomatedPassive( aFileName ); // ignore return value
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CProEngToneHandler::IsProtected
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 TBool CProEngToneHandler::IsProtected( const TDesC& aFileName ) const
       
   279     {
       
   280     TBool result = EFalse;
       
   281     TRAP_IGNORE( result = IsProtectedL( aFileName ) );
       
   282     return result;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CProEngToneHandler::IsProtectedL
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TBool CProEngToneHandler::IsProtectedL( const TDesC& aFileName ) const
       
   290     {
       
   291     TInt isProtected( EFalse );
       
   292    	ContentAccess::TVirtualPathPtr path( aFileName,
       
   293    						ContentAccess::KDefaultContentObject );
       
   294    	CData* data = CData::NewLC( path, EContentShareReadWrite );
       
   295    	TInt result = data->GetAttribute( EIsProtected, isProtected );
       
   296    	CleanupStack::PopAndDestroy(); // data
       
   297 
       
   298     return( ( result == DRMCommon::EOk ) && isProtected );
       
   299     }
       
   300 
       
   301 //  End of File