scrsaver/scrsaverplugins/ScreenSaverAnimPlugin/src/ScreenSaverAnimPluginHelper.cpp
branchRCL_3
changeset 26 e8d784ac1a4b
equal deleted inserted replaced
25:aaeeca1f15af 26:e8d784ac1a4b
       
     1 /*
       
     2 * Copyright (c) 2005 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:   This file implements all helper classes 
       
    15 *                for ScreenSaverAnimPlugin
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include    <DRMHelper.h>
       
    24 #include    <coemain.h>
       
    25 #include    <apgcli.h>
       
    26 #include    <barsread.h>
       
    27 #include    <aknnotewrappers.h>
       
    28 #include    <centralrepository.h>
       
    29 
       
    30 #include    <screensaveranimplugin.rsg>
       
    31 
       
    32 #include    "ScreenSaverAnimPluginHelper.h"
       
    33 #include    "ScreenSaverAnimPlugin.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CScreenSaverAnimPluginVerifier::CScreenSaverAnimPluginVerifier
       
    39 // C++ default constructor can NOT contain any code, that might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CScreenSaverAnimPluginVerifier::CScreenSaverAnimPluginVerifier(
       
    43              CScreenSaverAnimPlugin* aFileVerify ) :
       
    44              iFileVerify( aFileVerify )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CScreenSaverAnimPluginVerifier::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CScreenSaverAnimPluginVerifier::ConstructL()
       
    54     {
       
    55     iCoeEnv = CCoeEnv::Static();
       
    56     iDRMHelper = CDRMHelper::NewL( *iCoeEnv );
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CScreenSaverAnimPluginVerifier::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CScreenSaverAnimPluginVerifier* CScreenSaverAnimPluginVerifier::NewL(
       
    65                                 CScreenSaverAnimPlugin* aFileVerify )
       
    66     {
       
    67     CScreenSaverAnimPluginVerifier* self = new( ELeave ) 
       
    68                             CScreenSaverAnimPluginVerifier( aFileVerify );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74     
       
    75 // -----------------------------------------------------------------------------
       
    76 // CScreenSaverAnimPluginVerifier::~CScreenSaverAnimPluginVerifier
       
    77 // Destructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CScreenSaverAnimPluginVerifier::~CScreenSaverAnimPluginVerifier()
       
    81     {
       
    82     delete iDRMHelper;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CScreenSaverAnimPluginVerifier::IsFileValidL
       
    87 // Empty implementation.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TBool CScreenSaverAnimPluginVerifier::VerifySelectionL( const MDesCArray* 
       
    91                                                         aSelectedFiles )
       
    92     {    
       
    93 
       
    94     TBool canbeautomated( EFalse );
       
    95 
       
    96     if( aSelectedFiles->MdcaCount()<1 )
       
    97         {
       
    98         // Download item
       
    99         return ETrue;
       
   100         }
       
   101 
       
   102     // 1. Check whether the drm rights are ok
       
   103     TInt res = 0;
       
   104     iDRMHelper->SetAutomatedType( 
       
   105                    CDRMHelper::EAutomatedTypeScreenSaver );
       
   106     res = iDRMHelper->CanSetAutomated( aSelectedFiles->MdcaPoint( 0 ), canbeautomated );
       
   107     if ( KErrUnderflow == res )
       
   108         {
       
   109         TInt resourceId = R_SANIM_ERROR_WRONG_FORMAT;
       
   110         // Show information note
       
   111         ShowErrorNoteL( resourceId );    
       
   112         return EFalse;        
       
   113         }
       
   114     if ( res )
       
   115         {
       
   116         iDRMHelper->HandleErrorL( res, aSelectedFiles->MdcaPoint( 0 ) );        
       
   117         return canbeautomated;
       
   118         }   
       
   119     else if ( !canbeautomated )
       
   120         {
       
   121         ShowErrorNoteL( R_DRM_PREV_RIGHTS_SET );
       
   122         return canbeautomated;
       
   123         }
       
   124 
       
   125     // 2. Check whether the file is supported
       
   126     RApaLsSession ls;
       
   127     CleanupClosePushL( ls );
       
   128     TUid dummyUid( KNullUid );
       
   129     TDataType dataType;
       
   130     User::LeaveIfError( ls.Connect() );
       
   131     // find the mimetype
       
   132     User::LeaveIfError( ls.AppForDocument( aSelectedFiles->MdcaPoint( 0 ), 
       
   133                 dummyUid, dataType ) );               
       
   134                     
       
   135     CleanupStack::PopAndDestroy( &ls );
       
   136 
       
   137     TResourceReader reader;
       
   138     TBool valid( EFalse );
       
   139     iCoeEnv->CreateResourceReaderLC( reader, 
       
   140                              R_MIMETYPE_SPECIFIC_PLUGIN_ARRAY );
       
   141     TInt countResource = reader.ReadInt16();
       
   142 
       
   143     for ( TInt i = 0; i < countResource; i++ )
       
   144         {
       
   145         HBufC* newMimeTypeEntry = reader.ReadHBufCL();        
       
   146         TPtr mimePtr( newMimeTypeEntry->Des() );
       
   147         reader.ReadInt32();
       
   148         if ( newMimeTypeEntry->Compare( dataType.Des() ) == 0 )
       
   149             {            
       
   150             valid =  ETrue;
       
   151             }
       
   152         delete newMimeTypeEntry;        
       
   153         }
       
   154     CleanupStack::PopAndDestroy(); // reader  
       
   155 
       
   156     if ( !valid )
       
   157         {
       
   158         // Pop a not supported error message             
       
   159         ShowErrorNoteL( R_SANIM_NOT_SUPPORTED );    
       
   160         return EFalse;
       
   161         }
       
   162 
       
   163     //3. Check file for Validity
       
   164     
       
   165     //Display the confirmation query when setting 
       
   166     //a DRM protected image as screensaver in General settings.
       
   167     TInt isCancel;
       
   168     isCancel = iDRMHelper->ShowAutomatedNote( aSelectedFiles->MdcaPoint( 0 ) ); 
       
   169     if ( KErrCancel == isCancel )
       
   170         {
       
   171         return EFalse;
       
   172         }
       
   173 
       
   174     
       
   175     TInt validity = KErrNone;
       
   176     TRAPD( err, 
       
   177        validity = iFileVerify->CheckFileValidityL( aSelectedFiles->MdcaPoint( 0 ) ));     
       
   178 
       
   179     if ( err )
       
   180         {
       
   181         // Dll may not be present
       
   182         ShowErrorNoteL( R_SANIM_NOT_SUPPORTED );
       
   183         return EFalse;
       
   184         }           
       
   185 
       
   186     if ( validity == KErrNoMemory )
       
   187         {
       
   188         // Pop up a Corrupted File message
       
   189         CEikonEnv::Static()->HandleError( validity );
       
   190         return EFalse;        
       
   191         }   
       
   192     else  if ( validity != KErrNone )
       
   193         {
       
   194         TInt resourceId = R_SANIM_ERROR_WRONG_FORMAT;
       
   195         // Show information note
       
   196         ShowErrorNoteL( resourceId );    
       
   197         return EFalse;        
       
   198         }
       
   199 
       
   200     return valid;
       
   201 
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CScreenSaverAnimPluginVerifier::ShowErrorNoteL
       
   206 // Displays the error note
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CScreenSaverAnimPluginVerifier::ShowErrorNoteL( TInt  aResourceId  ) const
       
   210     {
       
   211     HBufC* errorText = 
       
   212         iCoeEnv->AllocReadResourceLC( aResourceId );
       
   213     CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse );
       
   214     note->ExecuteLD( *errorText );
       
   215     CleanupStack::PopAndDestroy( errorText ); // errorText
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CScreensaverRepositoryWatcher::NewL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 CScreensaverRepositoryWatcher* CScreensaverRepositoryWatcher::NewL(
       
   223     const TUid aUid,
       
   224     const TUint32 aKey,
       
   225     CCenRepNotifyHandler::TCenRepKeyType aKeyType,
       
   226     TCallBack aCallBack,
       
   227     CRepository* aRepository )
       
   228     {
       
   229     CScreensaverRepositoryWatcher* self = new( ELeave ) 
       
   230           CScreensaverRepositoryWatcher( aUid, aKey, aCallBack, aRepository );
       
   231 
       
   232     CleanupStack::PushL( self );
       
   233     self->ConstructL( aKeyType );
       
   234     CleanupStack::Pop( self );
       
   235 
       
   236     return self;
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CScreensaverRepositoryWatcher::NewL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 CScreensaverRepositoryWatcher* CScreensaverRepositoryWatcher::NewL(
       
   244     const TUid aUid,
       
   245     TCallBack aCallBack,
       
   246     CRepository* aRepository )
       
   247     {
       
   248     CScreensaverRepositoryWatcher* self = new( ELeave ) CScreensaverRepositoryWatcher(
       
   249         aUid, NCentralRepositoryConstants::KInvalidNotificationId, aCallBack, aRepository );
       
   250 
       
   251     CleanupStack::PushL( self );
       
   252     self->ConstructL();
       
   253     CleanupStack::Pop( self );
       
   254 
       
   255     return self;
       
   256     }
       
   257 
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CScreensaverRepositoryWatcher::~CScreensaverRepositoryWatcher
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 CScreensaverRepositoryWatcher::~CScreensaverRepositoryWatcher()
       
   264     {
       
   265     if ( iNotifyHandler )
       
   266         {
       
   267         iNotifyHandler->StopListening();
       
   268         delete iNotifyHandler;      
       
   269         }
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CScreensaverRepositoryWatcher::CScreensaverRepositoryWatcher
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 CScreensaverRepositoryWatcher::CScreensaverRepositoryWatcher(
       
   277     const TUid aUid,
       
   278     const TUint32 aKey,
       
   279     TCallBack aCallBack,
       
   280     CRepository* aRepository )
       
   281     :
       
   282     iUid( aUid ), iKey( aKey ), iCallBack( aCallBack ), iRepository( aRepository )
       
   283     {
       
   284     }
       
   285 
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CScreensaverRepositoryWatcher::ConstructL
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CScreensaverRepositoryWatcher::ConstructL(CCenRepNotifyHandler::TCenRepKeyType aKeyType)
       
   292     {
       
   293     iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository, aKeyType, iKey );
       
   294     iNotifyHandler->StartListeningL();
       
   295     }
       
   296 
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CScreensaverRepositoryWatcher::ConstructL
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void CScreensaverRepositoryWatcher::ConstructL()
       
   303     {
       
   304     iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository );
       
   305     iNotifyHandler->StartListeningL();
       
   306     }
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CScreensaverRepositoryWatcher::ChangedKey
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 TUint32 CScreensaverRepositoryWatcher::ChangedKey()
       
   314     {
       
   315     return iChangedKey;
       
   316     }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CScreensaverRepositoryWatcher::HandleNotifyInt
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CScreensaverRepositoryWatcher::HandleNotifyInt( 
       
   323                                     TUint32 aKey, TInt /*aNewValue*/ )
       
   324     {
       
   325     iChangedKey = aKey;
       
   326     iCallBack.CallBack();
       
   327     iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId;
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CScreensaverRepositoryWatcher::HandleNotifyString
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CScreensaverRepositoryWatcher::HandleNotifyString( TUint32 aKey, 
       
   335                                                      const TDesC16& /*aNewValue*/ )
       
   336     {  
       
   337     iChangedKey = aKey;
       
   338     iCallBack.CallBack();
       
   339     iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId;
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CScreensaverRepositoryWatcher::HandleNotifyGeneric
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CScreensaverRepositoryWatcher::HandleNotifyGeneric(TUint32 aKey)
       
   347     {
       
   348     iChangedKey = aKey;
       
   349     iCallBack.CallBack();
       
   350     iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId;
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CScreensaverRepositoryWatcher::HandleNotifyError
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CScreensaverRepositoryWatcher::HandleNotifyError(TUint32 /*aKey*/, TInt /*aError*/, CCenRepNotifyHandler* /*aHandler*/)
       
   358     {
       
   359     }     
       
   360 
       
   361 // End of File