commondrm/drmrightsmanagerui/src/DRMCommonUtilities.cpp
changeset 0 95b198f216e5
child 9 89a1f2bd800d
child 23 493788a4a8a4
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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:  Common utilities functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <stringloader.h>
       
    21 #include <aknquerydialog.h>
       
    22 #include <aknnotewrappers.h>
       
    23 #include <oma2agent.h>
       
    24 
       
    25 #include <drmrightsmanager.rsg>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 
       
    28 #include <utf.h>
       
    29 
       
    30 #include "drmcommonutilities.h"
       
    31 #include "drmrightsmgrapp.h"
       
    32 #include "drmuilogger.h"
       
    33 #include "drmrightsmgrappui.h"
       
    34 #include "drmutilityinternaltypes.h"
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // ROM folder
       
    39 _LIT( KDriveZ, "z:" );
       
    40 
       
    41 // Private folder
       
    42 _LIT( KPrivateFolder, "\\private" );
       
    43 _LIT( KSystemFolder, "\\system" );
       
    44 _LIT( KTempFolder, "\\temp" );
       
    45 
       
    46 // Name of the MBM file containing icons
       
    47 _LIT( KDRMUIMBMFile, "drmrightsmanager.mbm" );
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 // DRMCommonUtilities::ShowConfirmationQueryL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 TBool DRMCommonUtilities::ShowConfirmationQueryL( const TInt aResourceId,
       
    56                                                   const TDesC& aString,
       
    57                                                   CCoeEnv* aLoaderEnv )
       
    58     {
       
    59     HBufC* stringNote = StringLoader::LoadLC( aResourceId, aString,
       
    60                                               aLoaderEnv );
       
    61     TBool retVal = ShowConfirmationQueryL( *stringNote );
       
    62     CleanupStack::PopAndDestroy( stringNote ); // stringNote
       
    63 
       
    64     return retVal;
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // DRMCommonUtilities::ShowConfirmationQueryL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 TBool DRMCommonUtilities::ShowConfirmationQueryL( const TInt aResourceId,
       
    73                                                   CCoeEnv* aLoaderEnv )
       
    74     {
       
    75     HBufC* stringNote = StringLoader::LoadLC( aResourceId, aLoaderEnv );
       
    76     TBool retVal = ShowConfirmationQueryL( *stringNote );
       
    77     CleanupStack::PopAndDestroy( stringNote ); // stringNote
       
    78 
       
    79     return retVal;
       
    80     }
       
    81 
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // DRMCommonUtilities::ShowConfirmationQueryL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 TBool DRMCommonUtilities::ShowConfirmationQueryL( const TDesC& aPrompt )
       
    88     {
       
    89     CAknQueryDialog *queryDialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
    90 
       
    91     return queryDialog->ExecuteLD( R_DRM_CONFIRMATION_QUERY, aPrompt ) != 0;
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // DRMCommonUtilities::ShowConfirmationNoteL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void DRMCommonUtilities::ShowConfirmationNoteL( const TInt aResourceId,
       
   100                                                 const TDesC& aString,
       
   101                                                 CCoeEnv* aLoaderEnv )
       
   102     {
       
   103     HBufC* stringNote = StringLoader::LoadLC( aResourceId, aString,
       
   104                                               aLoaderEnv );
       
   105     ShowConfirmationNoteL( *stringNote );
       
   106     CleanupStack::PopAndDestroy( stringNote ); // stringNote
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // DRMCommonUtilities::ShowConfirmationNoteL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void DRMCommonUtilities::ShowConfirmationNoteL( const TInt aResourceId,
       
   115                                                 CCoeEnv* aLoaderEnv )
       
   116     {
       
   117     HBufC* stringNote = StringLoader::LoadLC( aResourceId, aLoaderEnv );
       
   118     ShowConfirmationNoteL( *stringNote );
       
   119     CleanupStack::PopAndDestroy( stringNote ); // stringNote
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // DRMCommonUtilities::ShowConfirmationNoteL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void DRMCommonUtilities::ShowConfirmationNoteL( const TDesC& aPrompt )
       
   128     {
       
   129     CAknConfirmationNote* confNote = new( ELeave )CAknConfirmationNote(
       
   130                                                                     ETrue );
       
   131     confNote->ExecuteLD( aPrompt );
       
   132     }
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // DRMCommonUtilities::ShowConfirmationNoteL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void DRMCommonUtilities::ShowInformationNoteL( const TInt aResourceId,
       
   140                                                CCoeEnv* aLoaderEnv )
       
   141     {
       
   142     HBufC* stringLabel = StringLoader::LoadLC( aResourceId, aLoaderEnv );
       
   143     CAknInformationNote* dialog = new( ELeave )CAknInformationNote( ETrue );
       
   144     dialog->ExecuteLD( *stringLabel );
       
   145     CleanupStack::PopAndDestroy( stringLabel );   // stringLabel
       
   146     }
       
   147 
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // DRMCommonUtilities::GetFutureActivationTime
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 TTime DRMCommonUtilities::GetFutureActivationTime( CDRMRights& aRights )
       
   154     {
       
   155     CDRMRightsConstraints* constraints = NULL;
       
   156     TTime playStartTime( Time::MaxTTime() );
       
   157     TTime displayStartTime( Time::MaxTTime() );
       
   158     TTime printStartTime( Time::MaxTTime() );
       
   159     TTime executeStartTime( Time::MaxTTime() );
       
   160 
       
   161     aRights.GetPlayRight( constraints );
       
   162     if ( constraints )
       
   163         {
       
   164         constraints->GetStartTime( playStartTime );
       
   165         delete constraints;
       
   166         constraints = NULL;
       
   167         }
       
   168 
       
   169     aRights.GetDisplayRight( constraints );
       
   170     if ( constraints )
       
   171         {
       
   172         constraints->GetStartTime( displayStartTime );
       
   173         delete constraints;
       
   174         constraints = NULL;
       
   175         }
       
   176 
       
   177     aRights.GetPrintRight( constraints );
       
   178     if ( constraints )
       
   179         {
       
   180         constraints->GetStartTime( printStartTime );
       
   181         delete constraints;
       
   182         constraints = NULL;
       
   183         }
       
   184 
       
   185     aRights.GetExecuteRight( constraints );
       
   186     if ( constraints )
       
   187         {
       
   188         constraints->GetStartTime( executeStartTime );
       
   189         delete constraints;
       
   190         constraints = NULL;
       
   191         }
       
   192 
       
   193     return ( Min( Min( playStartTime, displayStartTime ),
       
   194                   Min( printStartTime, executeStartTime ) ) );
       
   195     }
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // DRMCommonUtilities::GetIconsFileName
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void DRMCommonUtilities::GetIconsFileName( TDes& aIconsFileName )
       
   203     {
       
   204     aIconsFileName.Append( KDriveZ );
       
   205     aIconsFileName.Append( KDC_APP_BITMAP_DIR );
       
   206     aIconsFileName.Append( KDRMUIMBMFile );
       
   207 
       
   208     return;
       
   209     }
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // DRMCommonUtilities::IsInPrivateFolderL
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 TBool DRMCommonUtilities::IsInPrivateFolderL( const TDesC& aContentPath )
       
   217     {
       
   218     TInt retval = EFalse;
       
   219     TParse path;
       
   220     User::LeaveIfError( path.Set( KNullDesC, &aContentPath, NULL ) );
       
   221 
       
   222     HBufC* driveBuf = HBufC::NewLC( KMaxFileName );
       
   223 
       
   224     TPtr driveAndPath( const_cast<TUint16*>( driveBuf->Ptr()), 0, KMaxFileName );
       
   225     driveAndPath = path.DriveAndPath();
       
   226     driveAndPath.LowerCase();
       
   227 
       
   228     retval = ( driveAndPath.Find( KPrivateFolder ) == path.Drive().Length() ||
       
   229                driveAndPath.Find( KSystemFolder ) == path.Drive().Length() ||
       
   230                driveAndPath.Find( KTempFolder ) == path.Drive().Length() );
       
   231     CleanupStack::PopAndDestroy( driveBuf );
       
   232     return retval;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // DRMCommonUtilities::RightsIssuerUrlL
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 TInt DRMCommonUtilities::RightsIssuerUrlL( const TFileName& aFileName,
       
   240                                            HBufC*& aRightsIssuerURL )
       
   241     {
       
   242     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
   243     TBuf<KUrlMaxLen> rightsIssuer;
       
   244     TInt retval( KErrNone );
       
   245 
       
   246     CData* content = NULL;
       
   247     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
   248     if ( r == KErrInUse )
       
   249         {
       
   250         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
   251         }
       
   252     else if ( r != KErrNone )
       
   253         {
       
   254         retval = r;
       
   255         }
       
   256 
       
   257     CleanupStack::PushL( content );
       
   258 
       
   259     if ( retval == KErrNone )
       
   260         {
       
   261         // Get value of rights-issuer header field
       
   262         retval = content->GetStringAttribute( ERightsIssuerUrl, rightsIssuer );
       
   263         if ( ( retval == KErrNone ) && ( rightsIssuer.Length() != 0 ) )
       
   264             {
       
   265             aRightsIssuerURL = rightsIssuer.AllocL();
       
   266             }
       
   267         else
       
   268             {
       
   269             delete aRightsIssuerURL;
       
   270             aRightsIssuerURL = NULL;
       
   271             retval = KErrNotFound;
       
   272             }
       
   273         }
       
   274     CleanupStack::PopAndDestroy( content );
       
   275     return retval;
       
   276     }
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // DRMCommonUtilities::GetRightsStatus
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TInt DRMCommonUtilities::GetRightsStatus( CDRMRights& aRights,
       
   284                                           CDRMRights::TExpiration& aExpir)
       
   285     {
       
   286     TUint32 constraintSpec = 0;
       
   287     CDRMRights::TRestriction restriction;
       
   288     TUint32 constType;
       
   289     TInt err = KErrNone;
       
   290 
       
   291     err = aRights.GetRightsInfo( constraintSpec, restriction, aExpir, constType );
       
   292 
       
   293     return err;
       
   294     }
       
   295 
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // DRMCommonUtilities::ParseParametersAndStartL
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void DRMCommonUtilities::ParseParametersAndStartL( TLex aLex,
       
   302                                                    TBool aStartEmbedded,
       
   303                                                    CDRMRightsMgrAppUi& aAppUi )
       
   304     {
       
   305     CArrayFixFlat<TPtrC>* params;       // array of parameters
       
   306     HBufC* url16( NULL );
       
   307     HBufC* fullName( NULL );
       
   308     TUint32 drmScheme( EDrmSchemeUnknownDrm );
       
   309     params = new( ELeave )CArrayFixFlat<TPtrC>( sizeof( TPtrC ) );
       
   310     CleanupStack::PushL( params );
       
   311 
       
   312     while ( !aLex.Eos() )                // Extract the parameters
       
   313         {
       
   314         params->AppendL( aLex.NextToken() );
       
   315         }
       
   316 
       
   317     TInt startParam = KMaxTInt;
       
   318 
       
   319     // Parse the DRM Rights Manager launch parameter string. First parameter
       
   320     // indicates the launching type (embedded, stand alone, embedded with full
       
   321     // path name parameter or stand alone with full path name parameter), second
       
   322     // parameter is Local ID for OMA DRM file, third one is the content URI in
       
   323     // case of OMA DRM and full file path name in case of WM DRM, whereas the fourth
       
   324     // parameter indicates the DRM protection scheme of the file for which the
       
   325     // details view has been launched. The fifth parameter is the full file path in
       
   326     // case of an OMA DRM file.
       
   327     TLex lexStart ( params->At( 0 ) );
       
   328 
       
   329     // First parameter: type of operation to be performed
       
   330     User::LeaveIfError( lexStart.Val( startParam ) );
       
   331 
       
   332     if ( ( aStartEmbedded && ( startParam == EDrmLaunchParamEmbeddedHelper ||
       
   333         startParam == EDrmLaunchParamEmbeddedUtility ) ) ||
       
   334          ( !aStartEmbedded && ( startParam == EDrmLaunchParamStandAloneHelper ||
       
   335         startParam == EDrmLaunchParamStandAloneUtility ) ) )
       
   336         {
       
   337         TUint32 localID;
       
   338 
       
   339         TLex lexLocalID ( params->At( 1 ) );
       
   340 
       
   341         // Second parameter: LocalID
       
   342         User::LeaveIfError( lexLocalID.Val( localID, EDecimal ) );
       
   343 
       
   344         // Third parameter: Content URI
       
   345         HBufC8* contentURI = HBufC8::NewLC( params->At( 2 ).Length() );
       
   346         contentURI->Des().Copy( params->At( 2 ) );
       
   347 
       
   348         if ( params->Count() > 3 && ( startParam == EDrmLaunchParamEmbeddedUtility
       
   349             || startParam == EDrmLaunchParamStandAloneUtility ) )
       
   350             {
       
   351 
       
   352             // Fourth parameter: DRM protection scheme
       
   353             TLex lexDrmType( params->At( 3 ) );
       
   354             lexDrmType.Val( drmScheme, EDecimal );
       
   355 
       
   356             TParse parser;
       
   357 
       
   358             if ( drmScheme == EDrmSchemeWmDrm )
       
   359                 {
       
   360                 // We have a WM DRM file
       
   361                 // Find out the file name and the item name and store them to
       
   362                 // the file details.
       
   363                 url16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   364                     contentURI->Des() );
       
   365                 CleanupStack::PushL( url16 );
       
   366 
       
   367                 if ( url16 )
       
   368                     {
       
   369                     // The received fourth parameter already has the
       
   370                     // full path name
       
   371                     aAppUi.SetSelectedItemFullName( url16->Des() );
       
   372                     User::LeaveIfError( parser.Set( url16->Des(), NULL, NULL ) );
       
   373                     // Get the file name and extension
       
   374                     aAppUi.SetSelectedItemName( parser.NameAndExt() );
       
   375                     }
       
   376                 CleanupStack::PopAndDestroy( url16 );
       
   377                 }
       
   378 
       
   379             // Fifth parameter: Full file path for OMA DRM
       
   380             if ( drmScheme == EDrmSchemeOmaDrm &&
       
   381                 ( startParam == EDrmLaunchParamEmbeddedUtility ||
       
   382                 startParam == EDrmLaunchParamStandAloneUtility ) )
       
   383                 {
       
   384                 // Find out the file name and the item name and store them to
       
   385                 // the file details.
       
   386                 fullName = HBufC::NewLC( params->At( 4 ).Length() );
       
   387                 fullName->Des().Copy( params->At( 4 ) );
       
   388 
       
   389                 aAppUi.SetSelectedItemFullName( fullName->Des() );
       
   390                 User::LeaveIfError( parser.Set( fullName->Des(), NULL, NULL ) );
       
   391                 // Get the file name and extension
       
   392                 aAppUi.SetSelectedItemName( parser.NameAndExt() );
       
   393                 CleanupStack::PopAndDestroy( fullName );
       
   394                 }
       
   395             }
       
   396         else
       
   397             {
       
   398             // DRM Helper has launched DRM Rights Manager. Currently DRM Helper
       
   399             // blocks attempts to launch DRM Rights Manager for both the plain
       
   400             // and WM DRM content.
       
   401             drmScheme = EDrmSchemeOmaDrm;
       
   402             }
       
   403 
       
   404         aAppUi.StartOnlyForDetailsL( *contentURI, localID, aStartEmbedded,
       
   405             drmScheme );
       
   406 
       
   407         CleanupStack::PopAndDestroy( contentURI );
       
   408         }
       
   409 
       
   410     CleanupStack::PopAndDestroy( params );
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // DRMCommonUtilities::SplitPath
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 TPtrC DRMCommonUtilities::SplitPath( const TDesC& aFileName, TPtrC& aRestOfName )
       
   418     {
       
   419     TPtrC ptr( KNullDesC );
       
   420     TInt pos = aFileName.Locate('\\'); // first backslash
       
   421     TInt length = aFileName.Length();
       
   422 
       
   423     if ( pos != KErrNotFound && pos < length )
       
   424         {
       
   425         TInt totalPos = pos;
       
   426         TPtrC name1 = aFileName.Mid(totalPos + 1);
       
   427         pos = name1.Locate('\\'); // second backslash
       
   428         length = name1.Length();
       
   429 
       
   430         if ( pos != KErrNotFound && pos < length )
       
   431             {
       
   432             totalPos += pos + 1;
       
   433             TPtrC name2 = aFileName.Mid(totalPos + 1);
       
   434             pos = name2.Locate('\\'); // third backslash
       
   435             length = name2.Length();
       
   436 
       
   437             if ( pos != KErrNotFound && pos < length )
       
   438                 {
       
   439                 totalPos += pos + 1;
       
   440                 aRestOfName.Set( aFileName.Mid( totalPos + 1, aFileName.Length() - 1 - totalPos ));
       
   441                 // return the leftmost part of the filename up to third backslash
       
   442                 return aFileName.Mid(0, totalPos + 1);
       
   443                 }
       
   444             }
       
   445         }
       
   446     return ptr;
       
   447     }
       
   448 
       
   449 
       
   450 
       
   451 // End of File