mobilemessaging/msgmedia/src/MsgMediaInfo.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:  
       
    15 *       Base class for different media type info classes.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h> // CBase
       
    25 #include <apmstd.h>  // TDataType
       
    26 #include <f32file.h> // RFs, RFile
       
    27 #include <apgcli.h>  // RApaLsSession
       
    28 
       
    29 #include <caf/caf.h>
       
    30 #include <DRMCommon.h> // Just for error codes
       
    31 #include <DRMHelper.h>
       
    32 #include <fileprotectionresolver.h>
       
    33 
       
    34 #include "MsgMediaInfo.h"
       
    35 
       
    36 // EXTERNAL DATA STRUCTURES
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 // MACROS
       
    43 
       
    44 // LOCAL CONSTANTS AND MACROS
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 
       
    48 // LOCAL FUNCTION PROTOTYPES
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CMsgMediaInfo::NewL
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CMsgMediaInfo* CMsgMediaInfo::NewL( RFile& aFile, 
       
    60                                             TDataType& aMimeType,
       
    61                                             TMsgMediaType aMediaType )
       
    62     {
       
    63     CMsgMediaInfo* self = new( ELeave ) CMsgMediaInfo( aMimeType, aMediaType );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aFile );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMsgMediaInfo::CMsgMediaInfo
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CMsgMediaInfo::CMsgMediaInfo( TDataType& aDataType, TMsgMediaType aMediaType ):
       
    77     CActive( EPriorityLow ),
       
    78     iMimeType( aDataType ),
       
    79     iFileSize( 0 ),
       
    80     iModificationTime(),
       
    81     iMediaType( aMediaType ),
       
    82     iDuration( 0 ),
       
    83     iProtection( EFileProtNoProtection ),
       
    84     iParsed( EFalse ),
       
    85     iHandlerAppUid( KNullUid )
       
    86     {
       
    87     CActiveScheduler::Add( this );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMsgMediaInfo::ConstructL
       
    92 // Symbian 2nd phase constructor can leave.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CMsgMediaInfo::ConstructL( RFile& aFile )
       
    96     {
       
    97     TFileName fullName;
       
    98     User::LeaveIfError( aFile.FullName( fullName ) );
       
    99     User::LeaveIfError( aFile.Size( iFileSize ) );
       
   100     User::LeaveIfError( aFile.Modified( iModificationTime ) );
       
   101     iFullFilePath = fullName.AllocL();
       
   102     }
       
   103     
       
   104 // -----------------------------------------------------------------------------
       
   105 // Destructor
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CMsgMediaInfo::~CMsgMediaInfo()
       
   109     {
       
   110     Cancel();
       
   111     iObserver = NULL;
       
   112     iDRMHelper = NULL;
       
   113     iFile.Close();
       
   114     delete iFullFilePath;
       
   115     delete iContentURI;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CMsgMediaInfo::ParseInfoDetails
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C void CMsgMediaInfo::ParseInfoDetails( RFile& aFile, CDRMHelper& aDRMHelper, MMediaInfoObserver& aObserver )
       
   123     {
       
   124     iObserver = &aObserver;
       
   125     iDRMHelper = &aDRMHelper;
       
   126     iFile.Duplicate( aFile );
       
   127     // Actual parsing is done in RunL (of each media info class).
       
   128     CompleteSelf( KErrNone );
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CMsgMediaInfo::ParseInfoDetailsL
       
   133 //
       
   134 // Deprecated. Use the non-leaving version instead.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C void CMsgMediaInfo::ParseInfoDetailsL( RFile& aFile, CDRMHelper& aDRMHelper, MMediaInfoObserver& aObserver )
       
   138     {
       
   139     ParseInfoDetails( aFile, aDRMHelper, aObserver );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CMsgMediaInfo::SetFileL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void CMsgMediaInfo::SetFileL( RFile& aFile )
       
   147     {
       
   148     TBool oldParsed = iParsed;
       
   149     iParsed = EFalse;
       
   150 
       
   151     delete iFullFilePath;
       
   152     iFullFilePath = NULL;
       
   153     
       
   154     TFileName fullName;
       
   155     User::LeaveIfError( aFile.FullName( fullName ) );
       
   156     User::LeaveIfError( aFile.Size( iFileSize ) );
       
   157     User::LeaveIfError( aFile.Modified( iModificationTime ) );
       
   158     iFullFilePath = fullName.AllocL();
       
   159 
       
   160     iParsed = oldParsed;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CMsgMediaInfo::Corrupt
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 EXPORT_C TBool CMsgMediaInfo::Corrupt() const
       
   168     {
       
   169     TBool corrupt( ETrue );
       
   170     switch ( iParseError )
       
   171         {
       
   172         case KErrNone:
       
   173         case KErrNoMemory:
       
   174         case KErrInUse:
       
   175         case DRMCommon::ENoRights:
       
   176         case DRMCommon::ERightsExpired:
       
   177         case DRMCommon::EInvalidRights:
       
   178             corrupt = EFalse;
       
   179             break;
       
   180         default:
       
   181             // All other errors are interpreted as corrupt
       
   182             break;
       
   183         }
       
   184     return corrupt;
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CMsgMediaInfo::DoCancel
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CMsgMediaInfo::DoCancel()
       
   192     {
       
   193     iFile.Close();
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CMsgMediaInfo::RunL
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CMsgMediaInfo::RunL()
       
   201     {
       
   202     // Never fails since does actually nothing.
       
   203     iParsed = ETrue;
       
   204     CompleteObserver();
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CMsgMediaInfo::RunError
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 TInt CMsgMediaInfo::RunError( TInt aError )
       
   212     {
       
   213     CompleteSelf( aError );
       
   214     return KErrNone;
       
   215     }
       
   216 	
       
   217 // -----------------------------------------------------------------------------
       
   218 // CMsgMediaInfo::CompleteSelf
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CMsgMediaInfo::CompleteSelf( TInt aError )
       
   222     {
       
   223     iStatus = KRequestPending;
       
   224     TRequestStatus* pStatus = &iStatus;
       
   225     SetActive();
       
   226     User::RequestComplete( pStatus, aError );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CMsgMediaInfo::CompleteSelf
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CMsgMediaInfo::CompleteObserver()
       
   234     {
       
   235     iFile.Close();
       
   236     ReleaseRights();
       
   237     iDRMHelper = NULL;
       
   238     iObserver->MediaInfoParsed();
       
   239     iObserver = NULL;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CMsgMediaInfo::FreezeRights
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CMsgMediaInfo::FreezeRights()
       
   247     {
       
   248     if ( iProtection & ( EFileProtForwardLocked | EFileProtSuperDistributable ) &&
       
   249         iContentURI && iContentURI->Length() )
       
   250         {
       
   251         TInt err = iDRMHelper->Consume2(
       
   252             *iContentURI,
       
   253             ContentAccess::EInstall,
       
   254             CDRMHelper::EStart );
       
   255         if ( !err )
       
   256             {
       
   257             iConsumed = ETrue;
       
   258             }
       
   259         }
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CMsgMediaInfo::ReleaseRights
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CMsgMediaInfo::ReleaseRights()
       
   267     {
       
   268     if ( iConsumed )
       
   269         {
       
   270         /*TInt ignore =*/ 
       
   271         iDRMHelper->Consume2(
       
   272             *iContentURI,
       
   273             ContentAccess::EInstall,
       
   274             CDRMHelper::EFinish );
       
   275         iConsumed = EFalse;
       
   276         }
       
   277     }
       
   278 
       
   279 //  End of File