commondrm/drmrightsmanagerui/src/DRMRightsMgrAppUi.cpp
changeset 0 95b198f216e5
child 17 e16d72588c28
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:  Implementation of CDRMRightsMgrAppUi class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <dcfrep.h>
       
    21 #include <dcfentry.h>
       
    22 #include <drmcommon.h>
       
    23 #include <dcfcommon.h>
       
    24 #include <wmdrmagent.h> // for WMDRM file details view
       
    25 
       
    26 #include <drmrightsmanager.rsg>
       
    27 
       
    28 #include <aknwaitdialog.h>
       
    29 #include <aknlistquerydialog.h>
       
    30 #include <stringloader.h>
       
    31 #include <aknnavide.h>
       
    32 #include <akndef.h>
       
    33 #include <barsread.h>  // for resource reader
       
    34 #include <centralrepository.h>
       
    35 #include <coeutils.h>
       
    36 
       
    37 #include <starterclient.h>
       
    38 
       
    39 // character conversions
       
    40 #include <utf.h>
       
    41 
       
    42 // caf
       
    43 #include <caf/data.h>
       
    44 #include <caf/caftypes.h>
       
    45 
       
    46 #include "drmrightsmgrappui.h"
       
    47 #include "drmrightsmgrdetailsview.h"
       
    48 #include "drmrightsmgrdocument.h"
       
    49 #include "drmcommonutilities.h"
       
    50 #include "drmuilogger.h"
       
    51 #include "drmrightsmanagerprivatecrkeys.h"
       
    52 #include "drmclockclient.h"
       
    53 #include "drmutilityinternaltypes.h"
       
    54 
       
    55 #include "oma1dcf.h"
       
    56 #include "oma2dcf.h"
       
    57 // CONSTANTS
       
    58 _LIT8( Kflk, "flk:" );
       
    59 _LIT8( Kldf, "ldf:" );
       
    60 
       
    61 // ================= MEMBER FUNCTIONS =======================
       
    62 //
       
    63 // -----------------------------------------------------------------------------
       
    64 // CDRMRightsMgrAppUi::CDRMRightsMgrAppUi
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CDRMRightsMgrAppUi::CDRMRightsMgrAppUi()
       
    68 : iStartEmbedded( EFalse ),
       
    69   iStatusScan( EDRMStatusFinished ),
       
    70   iDrmScheme( EDrmSchemeUnknownDrm ),
       
    71   iLocalID( 0 ),
       
    72   iContentURI( NULL ),
       
    73   iForegroundHasBeenActive( EFalse )
       
    74     {
       
    75     CLOG_WRITE( "CDRMRightsMgrAppUi::CDRMRightsMgrAppUi" );
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // void CDRMRightsMgrAppUi::ConstructL
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 void CDRMRightsMgrAppUi::ConstructL()
       
    84     {
       
    85     CLOG_WRITE( "-->ConstructL" );
       
    86     
       
    87     iCoeEnv->AddForegroundObserverL( *this );
       
    88     
       
    89     CDRMRightsMgrDetailsView* detailsView( NULL );
       
    90 
       
    91     BaseConstructL( EAknEnableSkin | EAppOrientationAutomatic | 
       
    92     	EAknEnableMSK | EAknSingleClickCompatible  );
       
    93 
       
    94     User::LeaveIfError( iRightsClient.Connect() );
       
    95     iDRMCommon = DRMCommon::NewL();
       
    96     if ( !iDRMCommon )
       
    97         {
       
    98         ProcessEngineErrorL( ETrue );
       
    99         }
       
   100 
       
   101     iStartEmbedded = iEikonEnv->StartedAsServerApp();
       
   102 
       
   103     // Create details view
       
   104     if ( iStartEmbedded )
       
   105         {
       
   106         detailsView = CDRMRightsMgrDetailsView::NewLC( ETrue );
       
   107         }
       
   108     else
       
   109         {
       
   110         detailsView = CDRMRightsMgrDetailsView::NewLC( EFalse );
       
   111         }
       
   112 
       
   113     AddViewL( detailsView );      // transfer ownership to CAknViewAppUi
       
   114     CleanupStack::Pop( detailsView );
       
   115     }
       
   116 
       
   117 
       
   118 // ----------------------------------------------------
       
   119 // CDRMRightsMgrAppUi::~CDRMRightsMgrAppUi
       
   120 // ----------------------------------------------------
       
   121 //
       
   122 CDRMRightsMgrAppUi::~CDRMRightsMgrAppUi()
       
   123     {
       
   124     
       
   125     iCoeEnv->RemoveForegroundObserver( *this );
       
   126     
       
   127     delete iWaitDialog;
       
   128 
       
   129     delete iDRMCommon;
       
   130 
       
   131     iRightsClient.Close();
       
   132 
       
   133     if ( iStartEmbedded && iDoorObserver )
       
   134         {
       
   135         iDoorObserver->NotifyExit( MApaEmbeddedDocObserver::ENoChanges );
       
   136         }
       
   137         
       
   138     if ( iContentURI )
       
   139         {
       
   140         delete iContentURI;
       
   141         }
       
   142         
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // CDRMRightsMgrAppUi::HandleKeyEventL
       
   148 // ---------------------------------------------------------
       
   149 //
       
   150 TKeyResponse CDRMRightsMgrAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
       
   151                                                   TEventCode /*aType*/ )
       
   152     {
       
   153     TChar charCode( aKeyEvent.iCode );
       
   154 
       
   155     if ( charCode == EKeyEnter )
       
   156         // Default is to show details
       
   157         {
       
   158         TInt command = EDRMRightsManagerCmdAppViewDet;
       
   159         HandleCommandL( command );
       
   160         return EKeyWasConsumed;
       
   161         }
       
   162     else if ( charCode == EKeyLeftArrow || charCode == EKeyRightArrow
       
   163         || charCode == EKeyBackspace )
       
   164         {
       
   165         return EKeyWasConsumed;
       
   166         }
       
   167 
       
   168     return EKeyWasNotConsumed;
       
   169     }
       
   170 
       
   171 
       
   172 // ----------------------------------------------------
       
   173 // CDRMRightsMgrAppUi::HandleCommandL
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CDRMRightsMgrAppUi::HandleCommandL( TInt aCommand )
       
   177     {
       
   178 
       
   179     switch ( aCommand )
       
   180         {
       
   181         case EEikCmdExit:
       
   182         case EAknSoftkeyExit:
       
   183             {
       
   184             Exit();
       
   185             break;
       
   186             }
       
   187         default:
       
   188             break;
       
   189         }
       
   190     }
       
   191 
       
   192 
       
   193 // ----------------------------------------------------
       
   194 // CDRMRightsMgrAppUi::StartOnlyForDetailsL
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CDRMRightsMgrAppUi::StartOnlyForDetailsL( const TDesC8& aContentURI,
       
   198                                                const TUint32 aLocalID,
       
   199                                                const TBool aEmbedded,
       
   200                                                const TInt aDrmScheme )
       
   201     {
       
   202 
       
   203     // Store the content related information when the details view 
       
   204     // is to be shown for the first time so that the information will be
       
   205     // available for details view refreshing in the future.
       
   206     if ( !iContentURI )
       
   207         {
       
   208         iDrmScheme = aDrmScheme;
       
   209         iLocalID = aLocalID;
       
   210         iContentURI = aContentURI.AllocL();
       
   211         }
       
   212     
       
   213     // For storing WM DRM rights information
       
   214     ContentAccess::RStreamablePtrArray<ContentAccess::CRightsInfo> array;
       
   215     CleanupClosePushL( array );
       
   216 
       
   217     TInt status( KErrCANoRights );
       
   218     CDRMRights* rights = NULL;
       
   219 
       
   220     if ( aEmbedded )
       
   221         {
       
   222         iStatusScan = EDRMStatusOpeningEmbedded;
       
   223         }
       
   224     else
       
   225         {
       
   226         iStatusScan = EDRMStatusOpening;
       
   227         }
       
   228 
       
   229     // Check the status of rights. Currently supports OMA and WM DRM.
       
   230     switch ( iDrmScheme )
       
   231         {
       
   232         case EDrmSchemeOmaDrm:
       
   233             CheckOmaDrmRightsL( aContentURI, aLocalID, rights, status );
       
   234             if ( status ) 
       
   235                 {
       
   236                 rights = NULL;
       
   237                 }
       
   238             break;
       
   239 
       
   240         case EDrmSchemeWmDrm:
       
   241             CheckWmDrmRightsL( aContentURI, status, array );
       
   242             break;
       
   243 
       
   244         default:
       
   245             break;
       
   246         }
       
   247 
       
   248     TFileName itemName;
       
   249     TFileName fullName;
       
   250 
       
   251     // Find the name and full name for the current item
       
   252     SelectedItemName( itemName );
       
   253     SelectedItemFullName( fullName );
       
   254 
       
   255     TUid uidView = TUid::Uid( EDRMDetailsView );
       
   256     CDRMRightsMgrDetailsView* detailsView =
       
   257                                 ( CDRMRightsMgrDetailsView* )View( uidView );
       
   258     if ( detailsView )
       
   259         {
       
   260         if ( !aEmbedded )
       
   261             {
       
   262             // If DRM Rights manager has not been launched as embedded,
       
   263             // activate details wiew as a local view.
       
   264             ActivateLocalViewL( uidView );
       
   265             }
       
   266 
       
   267             // Refresh the details view window with rights information of the
       
   268             // current item
       
   269             switch ( iDrmScheme )
       
   270                 {
       
   271                 case EDrmSchemeOmaDrm:
       
   272                     // Refresh the listbox
       
   273                     TRAP( status, detailsView->RefreshListBoxL( rights, itemName,
       
   274                         fullName, SelectedContentCanBeSent(), IndividualConstraint(),
       
   275                         UsageAllowed() ) );
       
   276                     break;
       
   277 
       
   278                 case EDrmSchemeWmDrm:
       
   279                     // WM DRM, Refresh the listbox
       
   280                     TRAP( status, detailsView->RefreshListBoxL( array,
       
   281                         itemName, fullName ) );
       
   282                     break;
       
   283 
       
   284                 default:
       
   285                     break;
       
   286                 }
       
   287 
       
   288             if ( status != KErrNone )
       
   289                 {
       
   290                 // If there was an error, show to the user
       
   291                 ProcessEngineErrorL( ETrue );
       
   292             }
       
   293         }
       
   294     if ( rights )
       
   295         {
       
   296         delete rights;
       
   297         }
       
   298 
       
   299     CleanupStack::PopAndDestroy( &array );
       
   300     }
       
   301 
       
   302 // ----------------------------------------------------------------------------
       
   303 // CDRMRightsMgrAppUi::CreateWaitDialogLC
       
   304 // ----------------------------------------------------------------------------
       
   305 //
       
   306 void CDRMRightsMgrAppUi::CreateWaitDialogLC()
       
   307     {
       
   308     if ( iWaitDialog )
       
   309         {
       
   310         delete iWaitDialog;
       
   311         iWaitDialog = NULL;
       
   312         }
       
   313 
       
   314     // Create WaitDialog with message and Cancel button
       
   315     iWaitDialog = new( ELeave )CAknWaitDialog( ( REINTERPRET_CAST(
       
   316                                 CEikDialog**, &iWaitDialog ) ), EFalse );
       
   317 
       
   318     iWaitDialog->SetCallback( this );
       
   319     iWaitDialog->PrepareLC( R_WAITNOTE );
       
   320 
       
   321     iWaitDialog->RunLD();
       
   322     }
       
   323 
       
   324 // ----------------------------------------------------------------------------
       
   325 // CDRMRightsMgrAppUi::GetItemNameL
       
   326 // ----------------------------------------------------------------------------
       
   327 //
       
   328 void CDRMRightsMgrAppUi::GetItemNameL( const TDesC& aFullName,
       
   329                                        TDes& aItemName,
       
   330                                        const TDesC8& aID,
       
   331                                        const TBool aIsGroup )
       
   332     {
       
   333     CDcfCommon* dcf = NULL;
       
   334     TBool getName = ETrue;
       
   335     TParse parse;
       
   336 
       
   337     // don't get the name if dealing with a file from a group
       
   338     if ( !aIsGroup )
       
   339         {
       
   340         TRAPD( r, dcf = CDcfCommon::NewL( aFullName ) );
       
   341         if ( r == KErrNone &&
       
   342              dcf &&
       
   343              dcf->iVersion == EOma2Dcf &&
       
   344              static_cast<COma2Dcf*>( dcf )->iGroupId )
       
   345             {
       
   346             getName = EFalse;
       
   347             parse.Set( aFullName, NULL, NULL );
       
   348             aItemName = parse.NameAndExt();
       
   349             }
       
   350         delete dcf;
       
   351         }
       
   352     if ( getName )
       
   353         {
       
   354         HBufC* itemNameBuf = NULL;
       
   355         TInt err = iRightsClient.GetName( aID, itemNameBuf );
       
   356 
       
   357         if ( err == KErrNotFound || itemNameBuf->Length() == 0 )
       
   358             {
       
   359             if ( aIsGroup )
       
   360                 {
       
   361                 aItemName = aFullName;
       
   362                 }
       
   363             else
       
   364                 {
       
   365                 parse.Set( aFullName, NULL, NULL );
       
   366                 aItemName = parse.NameAndExt();
       
   367                 }
       
   368             }
       
   369         else if ( err == KErrNone )
       
   370             {
       
   371             aItemName = *itemNameBuf;
       
   372             }
       
   373         else
       
   374             {
       
   375             User::Leave( err );
       
   376             }
       
   377 
       
   378         if ( itemNameBuf )
       
   379             {
       
   380             delete itemNameBuf;
       
   381             }
       
   382         }
       
   383     }
       
   384 
       
   385 
       
   386 
       
   387 // ----------------------------------------------------------------------------
       
   388 // CDRMRightsMgrAppUi::GetItemDataL
       
   389 // ----------------------------------------------------------------------------
       
   390 //
       
   391 TInt CDRMRightsMgrAppUi::GetItemDataL( const TDesC& aFileName,
       
   392                                        const TDesC8& aContentURI,
       
   393                                        TBool& aListable,
       
   394                                        TBool& aSendable )
       
   395     {
       
   396     TInt retval( KErrNone );
       
   397     aSendable = aListable = EFalse;
       
   398     HBufC8* buffer;
       
   399 
       
   400     if ( DRMCommonUtilities::IsInPrivateFolderL( aFileName ) )
       
   401         {
       
   402         if ( aContentURI.Left( 4 ).Compare( Kflk ) == 0 )
       
   403             {
       
   404             // FL or CD content
       
   405             if ( iRightsClient.ForwardLockURI( buffer ) == KErrNone &&
       
   406                  buffer )
       
   407                 {
       
   408                 if ( aContentURI.Compare( *buffer ) != 0 ) //forward lock content?
       
   409                     {
       
   410                     // CD content
       
   411                     aListable = ETrue;
       
   412                     }
       
   413                 delete buffer;
       
   414                 }
       
   415             else
       
   416                 {
       
   417                 retval = KErrGeneral;
       
   418                 }
       
   419             }
       
   420         else if (aContentURI.Left( 4 ).Compare( Kldf ) != 0) //local data file?
       
   421             {
       
   422             // SD or OMA DRM2 content
       
   423             // also rights issuer url existence SHOULD be checked but not possible here
       
   424             aListable = aSendable = ETrue;
       
   425             }
       
   426         }
       
   427     else
       
   428         {
       
   429         if ( ConeUtils::FileExists( aFileName ) )
       
   430             {
       
   431             TInt protection;
       
   432             CData* content = NULL;
       
   433             TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
   434 
       
   435             TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
   436             if ( r == KErrInUse )
       
   437                 {
       
   438                 content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
   439                 }
       
   440             else if ( r != KErrNone )
       
   441                 {
       
   442                 retval = r;
       
   443                 }
       
   444             CleanupStack::PushL( content );
       
   445 
       
   446             if ( retval == KErrNone )
       
   447                 {
       
   448                 retval = content->GetAttribute( EDeliveryMethod, protection );
       
   449                 if ( retval == KErrNone )
       
   450                     {
       
   451                     aListable = ( protection == EOmaDrm1ForwardLockDcf ||
       
   452                                   protection == EOmaDrm1CombinedDelivery ||
       
   453                                   protection == EOmaDrm1CombinedDeliveryDcf ||
       
   454                                   protection == EOmaDrm1SeparateDelivery ||
       
   455                                   protection == EOmaDrm2 );
       
   456 
       
   457                     if ( protection == EOmaDrm1SeparateDelivery ||
       
   458                          protection == EOmaDrm2 )
       
   459                         {
       
   460                         TBuf<KUrlMaxLen> rightsIssuer;
       
   461 
       
   462                         // Get rights issuer URL
       
   463                         retval = content->GetStringAttribute( ERightsIssuerUrl, rightsIssuer );
       
   464                         if ( ( retval == KErrNone ) && ( rightsIssuer.Length() > 0 ) )
       
   465                             {
       
   466                             aSendable = ETrue;
       
   467                             }
       
   468                         else
       
   469                             {
       
   470                             // Can't be sent, any error returned can be ignored
       
   471                             aSendable = EFalse;
       
   472                             retval = KErrNone;
       
   473                             }
       
   474                         }
       
   475                     }
       
   476                 }
       
   477             CleanupStack::PopAndDestroy( content );
       
   478             }
       
   479         }
       
   480 
       
   481     return retval;
       
   482     }
       
   483 
       
   484 
       
   485 // ----------------------------------------------------------------------------
       
   486 // CDRMRightsMgrAppUi::DialogDismissedL
       
   487 // ----------------------------------------------------------------------------
       
   488 //
       
   489 void CDRMRightsMgrAppUi::DialogDismissedL( TInt aButtonId )
       
   490     {
       
   491     if ( aButtonId == -1 )
       
   492         {
       
   493         // When pressing cancel button.
       
   494         // Only cancel if we know that there is an outstanding request
       
   495         if ( iStatusScan == EDRMStatusOpening ||
       
   496              iStatusScan == EDRMStatusOpeningEmbedded )
       
   497             {
       
   498             // Issue cancel to service provider
       
   499             iRightsClient.Cancel();
       
   500 
       
   501             if ( iStatusScan == EDRMStatusOpening )
       
   502                 {
       
   503                 // Cancel pressed when opening application --> Exit
       
   504                 HandleCommandL( EEikCmdExit );
       
   505                 }
       
   506             else if ( iStatusScan == EDRMStatusOpeningEmbedded )
       
   507                 {
       
   508                 // Cancel pressed when opening application embedded -->
       
   509                 // Shut the app
       
   510                 RunAppShutter();
       
   511                 }
       
   512             }
       
   513         }
       
   514     }
       
   515 
       
   516 // ----------------------------------------------------
       
   517 // CDRMRightsMgrAppUi::HandleGainingForeground()
       
   518 // ----------------------------------------------------
       
   519 //
       
   520 void CDRMRightsMgrAppUi::HandleGainingForeground()
       
   521     {
       
   522     // Refresh details view when the details view is returned
       
   523     // from the background to the foreground.
       
   524     if ( iForegroundHasBeenActive && iContentURI )
       
   525         {
       
   526         StartOnlyForDetailsL( iContentURI->Des(), iLocalID, 
       
   527             iStartEmbedded, iDrmScheme );
       
   528         }
       
   529     }
       
   530 
       
   531 
       
   532 // ----------------------------------------------------
       
   533 // CDRMRightsMgrAppUi::HandleLosingForeground()
       
   534 // ----------------------------------------------------
       
   535 //
       
   536 void CDRMRightsMgrAppUi::HandleLosingForeground()
       
   537     {
       
   538     iForegroundHasBeenActive = ETrue;
       
   539     }
       
   540 
       
   541 // ----------------------------------------------------
       
   542 // CDRMRightsMgrAppUi::NotifyExit
       
   543 // ----------------------------------------------------
       
   544 //
       
   545 void CDRMRightsMgrAppUi::NotifyExit( TExitMode /*aMode*/ )
       
   546     {
       
   547     }
       
   548 
       
   549 
       
   550 // ----------------------------------------------------
       
   551 // CDRMRightsMgrAppUi::HandleResourceChangeL
       
   552 // ----------------------------------------------------
       
   553 //
       
   554 void CDRMRightsMgrAppUi::HandleResourceChangeL( TInt aType )
       
   555     {
       
   556 
       
   557     CAknViewAppUi::HandleResourceChangeL( aType );
       
   558 
       
   559     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   560         {
       
   561         TVwsViewId viewId;
       
   562         CDRMRightsMgrDetailsView* detailsView;
       
   563         if ( GetActiveViewId( viewId ) == KErrNone )
       
   564             {
       
   565             detailsView = ( CDRMRightsMgrDetailsView* )View( viewId.iViewUid );
       
   566             if ( detailsView )
       
   567                 {
       
   568                 detailsView->HandleClientRectChange();
       
   569                 }
       
   570             }
       
   571         else
       
   572             {
       
   573              detailsView = ( CDRMRightsMgrDetailsView* )View( TUid::Uid( EDRMDetailsView ) );
       
   574              if ( detailsView )
       
   575                 {
       
   576                 detailsView->HandleClientRectChange();
       
   577                 }
       
   578             }
       
   579         }
       
   580     }
       
   581 
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CDRMRightsMgrAppUi::ProcessCommandParametersL
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 TBool CDRMRightsMgrAppUi::ProcessCommandParametersL( TApaCommand aCommand,
       
   588                                                TFileName& aDocumentName,
       
   589                                                const TDesC8& /*aTail*/ )
       
   590     {
       
   591     if ( aCommand == EApaCommandOpen )
       
   592         {
       
   593         OpenDetailsViewNotEmbeddedL( aDocumentName );
       
   594         }
       
   595     else if ( !iStartEmbedded )
       
   596         {
       
   597         if ( IsForeground() )
       
   598             {
       
   599             ActivateLocalViewL( TUid::Uid( EDRMDetailsView ) );
       
   600             }
       
   601         }
       
   602 
       
   603     return EFalse;
       
   604     }
       
   605 
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CDRMRightsMgrAppUi::ProcessMessageL
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 void CDRMRightsMgrAppUi::ProcessMessageL( TUid /*aUid*/, const TDesC8& aParams )
       
   612     {
       
   613     HBufC16* buf16 = HBufC16::NewLC( aParams.Length() );
       
   614     buf16->Des().Copy( aParams );
       
   615     OpenDetailsViewNotEmbeddedL( *buf16 );
       
   616     CleanupStack::PopAndDestroy( buf16 );
       
   617     }
       
   618 
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CDRMRightsMgrAppUi::OpenDetailsViewNotEmbeddedL
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CDRMRightsMgrAppUi::OpenDetailsViewNotEmbeddedL( const TDesC& aParams )
       
   625     {
       
   626     TLex lex( aParams );
       
   627     DRMCommonUtilities::ParseParametersAndStartL( lex, EFalse, *this );
       
   628     }
       
   629 
       
   630 // ----------------------------------------------------------------------------
       
   631 // CDRMRightsMgrAppUi::ProcessEngineErrorL
       
   632 // ----------------------------------------------------------------------------
       
   633 //
       
   634 void CDRMRightsMgrAppUi::ProcessEngineErrorL( TBool aCloseImmediately )
       
   635     {
       
   636     if ( DRMCommonUtilities::ShowConfirmationQueryL(
       
   637                                                 R_QTN_DRM_MGR_QUERY_RESTART,
       
   638                                                 iEikonEnv ) )
       
   639         {
       
   640         RStarterSession starterSession;
       
   641         if ( starterSession.Connect() == KErrNone )
       
   642             {
       
   643             starterSession.Reset( RStarterSession::EUnknownReset );
       
   644             starterSession.Close();
       
   645             }
       
   646         }
       
   647 
       
   648     if ( aCloseImmediately )
       
   649         {
       
   650         HandleCommandL( EEikCmdExit ); // at least exit, if it doesn't restart
       
   651         }
       
   652     else
       
   653         {
       
   654         RunAppShutter();
       
   655         }
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CDrmRightsMgrAppUi::GetRightsManagerL
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 ContentAccess::CRightsManager* CDRMRightsMgrAppUi::GetRightsManagerL()
       
   663     {
       
   664     ContentAccess::CManager* manager( NULL );
       
   665     ContentAccess::CRightsManager* rightsManager( NULL );
       
   666     RArray<ContentAccess::TAgent> agents;
       
   667     TInt agent( 0 );
       
   668 
       
   669     CleanupClosePushL( agents );
       
   670     manager = ContentAccess::CManager::NewLC();
       
   671 
       
   672     manager->ListAgentsL( agents );
       
   673 
       
   674     for ( agent = 0; agent < agents.Count(); agent++ )
       
   675         {
       
   676         if (agents[agent].Name().Compare( KWmDrmAgentName ) == 0)
       
   677             {
       
   678             break;
       
   679             }
       
   680         }
       
   681 
       
   682     // If no WM DRM agent is found, leave
       
   683     if ( agent >= agents.Count() )
       
   684         {
       
   685         User::Leave( KErrNotSupported );
       
   686         }
       
   687 
       
   688 
       
   689     // Create a CRightsManager for the agent found
       
   690     rightsManager = manager->CreateRightsManagerL( agents[agent] );
       
   691 
       
   692     CleanupStack::PopAndDestroy( manager );
       
   693     CleanupStack::PopAndDestroy( &agents );
       
   694     return rightsManager;
       
   695     }
       
   696 
       
   697 // ---------------------------------------------------------
       
   698 // CDRMRightsMgrAppUi::CheckOmaDrmRightsL
       
   699 // ---------------------------------------------------------
       
   700 //
       
   701 void CDRMRightsMgrAppUi::CheckOmaDrmRightsL( const TDesC8& aContentURI,
       
   702                                              const TUint32 aLocalID,
       
   703                                              CDRMRights*& aRights,
       
   704                                              TInt& aStatus )
       
   705     {
       
   706     TBool listable( EFalse ), sendable( EFalse );
       
   707     TBool individualConstraint( EFalse ), usageAllowed( EFalse );
       
   708 
       
   709     CDcfRep* dcfRep = CDcfRep::NewL();
       
   710     CleanupStack::PushL( dcfRep );
       
   711 
       
   712     if ( dcfRep )
       
   713         {
       
   714         TRAPD( err, dcfRep->OrderListL( aContentURI ) );
       
   715         if ( !err )
       
   716             {
       
   717             TFileName fullName;
       
   718 
       
   719             CDcfEntry* entry = dcfRep->NextL();
       
   720             if ( entry )
       
   721                 {
       
   722                 fullName = entry->FileName();
       
   723                 delete entry;
       
   724                 SetSelectedItemFullName( fullName );
       
   725 
       
   726                 TFileName itemName;
       
   727                 GetItemNameL( fullName, itemName, aContentURI, EFalse );
       
   728                 SetSelectedItemName( itemName );
       
   729 
       
   730                 if ( GetItemDataL( fullName, aContentURI, listable,
       
   731                     sendable ) == KErrNone )
       
   732                     {
       
   733                     SetSelectedContentCanBeSent( sendable );
       
   734                     }
       
   735                 }
       
   736             }
       
   737         else // No related media was found
       
   738             {
       
   739             SetSelectedItemFullName( KNullDesC );
       
   740             TFileName itemName;
       
   741             GetItemNameL( KNullDesC, itemName, aContentURI, ETrue );
       
   742             SetSelectedItemName( itemName );
       
   743 
       
   744             SetSelectedContentCanBeSent( EFalse );
       
   745             }
       
   746         }
       
   747     else
       
   748         {
       
   749         User::Leave( KErrGeneral );
       
   750         }
       
   751 
       
   752     if ( aLocalID > 0 )
       
   753         {
       
   754         aStatus = iDRMCommon->GetSingleRightsObject( aContentURI,
       
   755             aLocalID, aRights );
       
   756         }
       
   757         else
       
   758         {
       
   759         aStatus = iDRMCommon->GetActiveRights( aContentURI, 0, aRights );
       
   760         }
       
   761     if ( aStatus )
       
   762         {
       
   763         aRights = NULL;
       
   764         }
       
   765 
       
   766     CheckIndividualConstraint( aContentURI, individualConstraint, usageAllowed );
       
   767     SetSelectedIndividualConstraint( individualConstraint );
       
   768     SetSelectedUsageAllowed( usageAllowed );
       
   769 
       
   770     CleanupStack::PopAndDestroy( dcfRep );
       
   771 
       
   772     // Do not show the note, show license information in the details view.
       
   773     }
       
   774 
       
   775 // ---------------------------------------------------------
       
   776 // CDRMRightsMgrAppUi::CheckWmDrmRightsL
       
   777 // ---------------------------------------------------------
       
   778 //
       
   779 void CDRMRightsMgrAppUi::CheckWmDrmRightsL( const TDesC8& aContentURI,
       
   780     TInt& aStatus, ContentAccess::RStreamablePtrArray<ContentAccess::CRightsInfo>& aArray )
       
   781     {
       
   782 
       
   783     ContentAccess::CRightsManager* manager( NULL );
       
   784     HBufC* url16( NULL );
       
   785 
       
   786     manager = GetRightsManagerL();
       
   787     CleanupStack::PushL( manager );
       
   788 
       
   789     url16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aContentURI );
       
   790     CleanupStack::PushL( url16 );
       
   791 
       
   792     // Wait note is not shown anymore when checking the rights.
       
   793     // Get the list of rights, if leave occurs then there are no rights
       
   794     // or the rights are expired.
       
   795     TRAP( aStatus, manager->ListRightsL( aArray, url16->Des() ) );
       
   796 
       
   797     if( aArray.Count() )
       
   798         {
       
   799         switch( aArray[0]->RightsStatus() )
       
   800             {
       
   801             // Rights don't exist
       
   802             case ContentAccess::ERightsStatusNone:
       
   803             case ContentAccess::ERightsStatusPending:
       
   804 
       
   805                 // Map the rights status
       
   806                 aStatus = KErrCANoRights;
       
   807                 break;
       
   808 
       
   809             // Rights exist:
       
   810             case ContentAccess::ERightsStatusValid:
       
   811             case ContentAccess::ERightsStatusExpired:
       
   812 
       
   813                 aStatus = KErrNone;
       
   814                 break;
       
   815 
       
   816             default:
       
   817                 aStatus = KErrCANoRights;
       
   818                 break;
       
   819             }
       
   820         }
       
   821     else
       
   822         {
       
   823         aStatus = KErrCANoRights;
       
   824         }
       
   825 
       
   826     CleanupStack::PopAndDestroy( url16 );
       
   827     CleanupStack::PopAndDestroy( manager );
       
   828     }
       
   829 
       
   830 // ---------------------------------------------------------
       
   831 // CDRMRightsMgrAppUi::CheckIndividualConstraintL
       
   832 // ---------------------------------------------------------
       
   833 //
       
   834 void CDRMRightsMgrAppUi::CheckIndividualConstraint( const TDesC8& aContentURI,
       
   835                                                     TBool& aIndividualConstraint,
       
   836                                                     TBool& aUsageAllowed )
       
   837     {
       
   838     RPointerArray<CDRMRights>* uriList = NULL;
       
   839     TInt r = KErrNone;
       
   840     TUint32 retval(0);
       
   841     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
       
   842     CDRMRightsConstraints* constraint = NULL;
       
   843     RDRMClockClient client;
       
   844     RDRMRightsClient rclient;
       
   845     TTime time;
       
   846     RPointerArray<HBufC8> individuals;
       
   847 
       
   848     r = client.Connect();
       
   849     if ( r == KErrNone )
       
   850         {
       
   851         TTime time;
       
   852         TInt timeZone(0);
       
   853         client.GetSecureTime(time, timeZone, secLevel);
       
   854         }
       
   855 
       
   856     r = iDRMCommon->GetDetailedContentRights(aContentURI, uriList);
       
   857     if ( r )
       
   858         {
       
   859         uriList=NULL;
       
   860         }
       
   861 
       
   862     r = KErrNone;
       
   863 
       
   864     if ( !uriList || !uriList->Count() )
       
   865         {
       
   866         // no rights found
       
   867         client.Close();
       
   868         delete uriList;
       
   869         uriList = NULL;
       
   870         }
       
   871     else
       
   872         {
       
   873         // supported IMSI information is provided by rights client
       
   874         r = rclient.Connect();
       
   875         if( r == KErrNone)
       
   876             {
       
   877             TRAP( r, r = rclient.GetSupportedIndividualsL( individuals ) );
       
   878             rclient.Close();
       
   879             }
       
   880 
       
   881         // Check only the first entry in the list. This is to be expanded to check
       
   882         // all the entries in the list.
       
   883         for(TInt i = 0; i < 1; ++i)
       
   884             {
       
   885             r = (*uriList)[i]->GetPlayRight(constraint);
       
   886             if ( r != KErrNone )
       
   887                 {
       
   888                 r = (*uriList)[i]->GetDisplayRight(constraint);
       
   889                 }
       
   890             if ( r != KErrNone )
       
   891                 {
       
   892                 r = (*uriList)[i]->GetExecuteRight(constraint);
       
   893                 }
       
   894             if ( r != KErrNone )
       
   895                 {
       
   896                 r = (*uriList)[i]->GetPrintRight(constraint);
       
   897                 }
       
   898             if ( r != KErrNone )
       
   899                 {
       
   900                 delete constraint;
       
   901                 constraint = NULL;
       
   902                 continue;
       
   903                 }
       
   904 
       
   905             if( constraint->GetConstraint().iActiveConstraints & EConstraintIndividual )
       
   906                 {
       
   907                 aIndividualConstraint = ETrue;
       
   908                 if ( constraint->GetConstraint().Valid( time, individuals, retval ) )
       
   909                     {
       
   910                     aUsageAllowed = ETrue;
       
   911                     }
       
   912                 }
       
   913             delete constraint;
       
   914             constraint = NULL;
       
   915             }
       
   916 
       
   917         client.Close();
       
   918         uriList->ResetAndDestroy();
       
   919 
       
   920         delete uriList;
       
   921         uriList = NULL;
       
   922         individuals.ResetAndDestroy();
       
   923         individuals.Close();
       
   924         }
       
   925     }
       
   926 
       
   927 // End of File