psln/pslnslidesetdialog/src/pslnslidesetdrmverifier.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2006 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:  DRM Verifier for slide set image sets.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "pslnslidesetdrmverifier.h"
       
    21 #include <pslnslidesetdialogrsc.rsg>
       
    22 #include <pslnslidesetdialoginterface.h>
       
    23 
       
    24 #include <DRMHelper.h>
       
    25 #include <aknnotewrappers.h>
       
    26 #include <StringLoader.h>
       
    27 
       
    28 const TInt KPslnDrmVerifyLimit = 50;
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // C++ constructor can NOT contain any code, that might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CPslnSlideSetDRMVerifier::CPslnSlideSetDRMVerifier(  TInt aType  ) 
       
    36     : iType ( aType )
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CPslnSlideSetDRMVerifier::ConstructL()
       
    45     {
       
    46     iDRMHelper = CDRMHelper::NewL( *CCoeEnv::Static() );
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPslnSlideSetDRMVerifier* CPslnSlideSetDRMVerifier::NewL( TInt aType )
       
    54     {
       
    55     CPslnSlideSetDRMVerifier* self = 
       
    56         new( ELeave ) CPslnSlideSetDRMVerifier( aType );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // Destructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CPslnSlideSetDRMVerifier::~CPslnSlideSetDRMVerifier()
       
    68     {
       
    69     delete iDRMHelper;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // Verifies user selected images. Used by MGFetch.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 TBool CPslnSlideSetDRMVerifier::VerifySelectionL( const MDesCArray* aSelectedFiles )
       
    77     {
       
    78     if ( aSelectedFiles )
       
    79         {
       
    80         if( aSelectedFiles->MdcaCount() < 1 )
       
    81             {
       
    82             // Download item
       
    83             return ETrue;
       
    84             }
       
    85         }
       
    86     else
       
    87         {
       
    88         // no aSelectedFiles.
       
    89         return EFalse;
       
    90         }
       
    91 
       
    92     TInt res = KErrNone;
       
    93     TBool canBeAutomated = EFalse;
       
    94     if ( iDRMHelper )
       
    95         {
       
    96         if ( iType == EPslnWallpaperDialog )
       
    97             {            
       
    98             res = iDRMHelper->SetAutomatedType( 
       
    99                 CDRMHelper::EAutomatedTypeWallpaper );
       
   100             }
       
   101         else
       
   102             {
       
   103             res = iDRMHelper->SetAutomatedType( 
       
   104                 CDRMHelper::EAutomatedTypeScreenSaver );
       
   105             }
       
   106         if ( res != KErrNone )
       
   107             {
       
   108             ShowErrorNoteL( R_PSLN_SLIDE_SET_DRM_ERROR );
       
   109             }
       
   110         else
       
   111             {
       
   112             // Go through the selected files.
       
   113             TInt fileCount = aSelectedFiles->MdcaCount() - 1;
       
   114             if ( fileCount > KPslnDrmVerifyLimit )
       
   115                 {
       
   116                 fileCount = KPslnDrmVerifyLimit;
       
   117                 }
       
   118             for ( TInt index = fileCount; index >= 0; index-- )
       
   119                 {
       
   120                 // First check DRM issues.
       
   121                 res = iDRMHelper->CanSetAutomated(
       
   122                     aSelectedFiles->MdcaPoint( index ),
       
   123                     canBeAutomated );
       
   124                 if ( !res && !canBeAutomated )
       
   125                     {
       
   126                     ShowErrorNoteL( R_PSLN_SLIDE_SET_DRM_ERROR );
       
   127                     }
       
   128                 else if( res == KErrUnderflow )
       
   129                     {
       
   130                     ShowErrorNoteL( R_PSLN_SLIDE_SET_IMAGE_CORRUPTED );
       
   131                     }
       
   132                 else if ( ( res != KErrNone ) || !canBeAutomated )
       
   133                     {
       
   134                     if ( iDRMHelper )
       
   135                         {
       
   136                         iDRMHelper->HandleErrorL(
       
   137                             res, 
       
   138                             aSelectedFiles->MdcaPoint( index ) );
       
   139                         }
       
   140                     }
       
   141                 else
       
   142                     {
       
   143                     // Empty.
       
   144                     }
       
   145                 }
       
   146             }
       
   147         }
       
   148     return canBeAutomated;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // Shows error note.
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CPslnSlideSetDRMVerifier::ShowErrorNoteL( TInt  aResourceId  ) const
       
   156     {
       
   157     HBufC* errorText = StringLoader::LoadLC( aResourceId );
       
   158     CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse );
       
   159     note->ExecuteLD( *errorText );
       
   160     CleanupStack::PopAndDestroy( errorText );
       
   161     }
       
   162 
       
   163 // End of file
       
   164