mobilemessaging/unieditor/application/src/UniEditorConvertVideoOperation.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006,2007 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:   CUniEditorConvertVideoOperation methods. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========== INCLUDE FILES ================================
       
    21 
       
    22 #include <apmstd.h>
       
    23 
       
    24 #include <centralrepository.h>
       
    25 
       
    26 #include <messagingvariant.hrh>
       
    27 #include <messaginginternalcrkeys.h> // for Central Repository keys
       
    28 
       
    29 #include <mmsconst.h>
       
    30 
       
    31 #include <MsgMediaResolver.h>
       
    32 #include <MsgVideoInfo.h>
       
    33 #include <MmsConformance.h>
       
    34 #include <MsgMimeTypes.h>
       
    35 
       
    36 #include <unimsventry.h>
       
    37 
       
    38 #include <mmsvattachmentmanager.h>
       
    39 #include <mmsvattachmentmanagersync.h>
       
    40 #include <cmsvattachment.h>
       
    41 
       
    42 #include <msgtextutils.h>
       
    43 
       
    44 #include "UniClientMtm.h"
       
    45 #include "UniEditorEnum.h"
       
    46 #include "UniEditorDocument.h"
       
    47 #include "UniEditorConvertVideoOperation.h"
       
    48 
       
    49 // ========== CONSTANTS ====================================
       
    50 _LIT8( KUniExtVideo3gp_8,  ".3gp" );
       
    51 // ========== MEMBER FUNCTIONS =============================
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CUniEditorConvertVideoOperation::NewL
       
    55 //
       
    56 // Factory method.
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CUniEditorConvertVideoOperation* CUniEditorConvertVideoOperation::NewL( 
       
    60         MUniEditorOperationObserver& aObserver,
       
    61         CUniEditorDocument& aDocument,
       
    62         RFs& aFs )
       
    63     {
       
    64     CUniEditorConvertVideoOperation* self = 
       
    65             new ( ELeave ) CUniEditorConvertVideoOperation( aObserver,
       
    66                                                             aDocument,
       
    67                                                             aFs );
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     CleanupStack::Pop( self );
       
    71     
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CUniEditorConvertVideoOperation::IsImplementedL
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 TBool CUniEditorConvertVideoOperation::IsImplementedL()
       
    80     {
       
    81     RImplInfoPtrArray implArray;
       
    82     CVideoConversionPlugin::ListImplementationsL( implArray );
       
    83     
       
    84     TBool result( EFalse );
       
    85     
       
    86     if ( implArray.Count() > 0)
       
    87         {
       
    88         result = ETrue;
       
    89         }    
       
    90         
       
    91     implArray.ResetAndDestroy();
       
    92     implArray.Close();
       
    93     
       
    94     return result;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CUniEditorConvertVideoOperation::CUniEditorConvertVideoOperation.
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 CUniEditorConvertVideoOperation::CUniEditorConvertVideoOperation(
       
   102         MUniEditorOperationObserver& aObserver,
       
   103         CUniEditorDocument& aDocument,
       
   104         RFs& aFs ) :
       
   105     CUniEditorOperation( aObserver, aDocument, aFs, EUniEditorOperationConvertVideo ),
       
   106     iTargetSize( 0 ),
       
   107     iNewAttaId( KMsvNullIndexEntryId )
       
   108     {
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CUniEditorConvertVideoOperation::ConstructL
       
   113 //
       
   114 // 2nd phase constructor.
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 void CUniEditorConvertVideoOperation::ConstructL()
       
   118     {
       
   119     BaseConstructL();
       
   120     
       
   121     RImplInfoPtrArray implArray;
       
   122     CVideoConversionPlugin::ListImplementationsL( implArray );
       
   123     
       
   124     if ( implArray.Count() > 0)
       
   125         {
       
   126         iConverter = CVideoConversionPlugin::NewL( implArray[0]->ImplementationUid() );    
       
   127         }
       
   128  
       
   129     implArray.ResetAndDestroy();
       
   130     implArray.Close();
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CUniEditorConvertVideoOperation::~CUniEditorConvertVideoOperation
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 CUniEditorConvertVideoOperation::~CUniEditorConvertVideoOperation()
       
   138     {
       
   139     Cancel();
       
   140     
       
   141     delete iNewVideoInfo;
       
   142     iNewVideoFile.Close();
       
   143     
       
   144     delete iEditStore;
       
   145     delete iConverter;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CUniEditorConvertVideoOperation::Process
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 void CUniEditorConvertVideoOperation::Process(
       
   153         CMsgVideoInfo* aVideoInfo,
       
   154         TMsvAttachmentId aAttachmentId,
       
   155         TInt aMessageSize )
       
   156     {
       
   157     ResetErrors();
       
   158     
       
   159     iVideoInfo = aVideoInfo;
       
   160     iAttachmentId = aAttachmentId;
       
   161     iTargetSize = aMessageSize;
       
   162     iOperationState = EUniConvertVidProcess;
       
   163     
       
   164     CompleteSelf( KErrNone );
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CUniEditorConvertVideoOperation::DetachAttachmentId
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 void CUniEditorConvertVideoOperation::DetachAttachmentId( TMsvAttachmentId& aAttachmentId )
       
   172     {
       
   173     // iNewVideoInfo may be already detached in DetachVideoInfo
       
   174     aAttachmentId = iNewAttaId;
       
   175     iNewAttaId = KMsvNullIndexEntryId;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CUniEditorConvertVideoOperation::RunL
       
   180 // ---------------------------------------------------------
       
   181 //
       
   182 void CUniEditorConvertVideoOperation::RunL()
       
   183     {
       
   184     PrintOperationAndState();
       
   185     if ( iStatus.Int() != KErrNone )
       
   186         {
       
   187         SetError( iStatus.Int() );
       
   188         iOperationState = EUniConvertVidError;
       
   189         }
       
   190     
       
   191     switch ( iOperationState )
       
   192         {
       
   193         case EUniConvertVidProcess:
       
   194             {
       
   195             DoStartProcessL();
       
   196             break;
       
   197             }
       
   198         case EUniConvertVidResolve:
       
   199             {
       
   200             DoStartResolveL();
       
   201             break;
       
   202             }
       
   203         case EUniConvertVidReady:
       
   204             {
       
   205             iObserver.EditorOperationEvent( EUniEditorOperationConvertVideo,
       
   206                                             EUniEditorOperationComplete );
       
   207             break;
       
   208             }
       
   209         case EUniConvertVidError:
       
   210             {
       
   211             DoErrorWithoutStateChange();
       
   212             iObserver.EditorOperationEvent( EUniEditorOperationConvertVideo,
       
   213                                             EUniEditorOperationError );
       
   214             break;
       
   215             }
       
   216         default:
       
   217             {
       
   218             iObserver.EditorOperationEvent( EUniEditorOperationConvertVideo,
       
   219                                             EUniEditorOperationError );
       
   220             break;
       
   221             }
       
   222         }    
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // CUniEditorConvertVideoOperation::DoCancelCleanup
       
   227 // ---------------------------------------------------------
       
   228 //
       
   229 void CUniEditorConvertVideoOperation::DoCancelCleanup()
       
   230     {
       
   231     if ( iConverter )
       
   232         {
       
   233         iConverter->CancelConvert();
       
   234         }
       
   235         
       
   236     DoErrorWithoutStateChange();
       
   237     }
       
   238 
       
   239   
       
   240 // ---------------------------------------------------------
       
   241 // CUniEditorConvertVideoOperation::DoStartProcessL
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CUniEditorConvertVideoOperation::DoStartProcessL()
       
   245     {
       
   246     //Create new attachment with .3rp extension
       
   247     CreateEmptyAttachmentL();
       
   248     
       
   249     RFile sourceFile = OpenFileForReadingL();
       
   250     
       
   251     iConverter->ConvertL ( sourceFile, iNewVideoFile, iTargetSize, *this );  
       
   252     SetPending();
       
   253     
       
   254     //We are responsble for closeing file handles
       
   255     sourceFile.Close();
       
   256     }
       
   257   
       
   258 // ---------------------------------------------------------
       
   259 // CUniEditorConvertVideoOperation::DoStartResolveL
       
   260 // ---------------------------------------------------------
       
   261 //
       
   262 void CUniEditorConvertVideoOperation::DoStartResolveL()
       
   263     {
       
   264     iNewVideoInfo = static_cast<CMsgVideoInfo*>(iDocument.DataModel()->MediaResolver().CreateMediaInfoL( iNewVideoFile ) );
       
   265     iDocument.DataModel()->MediaResolver().ParseInfoDetailsL( iNewVideoInfo, iNewVideoFile );
       
   266 
       
   267     iOperationState = EUniConvertVidReady;
       
   268 
       
   269     iNewVideoFile.Close();
       
   270     
       
   271     __ASSERT_DEBUG( iEditStore, Panic( EUniNullPointer ) );
       
   272     
       
   273     iEditStore->CommitL();
       
   274     delete iEditStore;
       
   275     iEditStore = NULL;
       
   276 
       
   277     CompleteSelf( KErrNone );
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------
       
   281 // CUniEditorConvertVideoOperation::DoErrorWithoutStateChange
       
   282 // ---------------------------------------------------------
       
   283 //
       
   284 void CUniEditorConvertVideoOperation::DoErrorWithoutStateChange()
       
   285     {
       
   286     iNewVideoFile.Close();
       
   287     
       
   288     delete iNewVideoInfo;
       
   289     iNewVideoInfo = NULL;
       
   290     
       
   291     delete iEditStore;
       
   292     iEditStore = NULL;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------
       
   296 // CUniEditorConvertVideoOperation::VideoConversionDone
       
   297 //
       
   298 // Video conversion callback implementation.
       
   299 // ---------------------------------------------------------
       
   300 //
       
   301 void CUniEditorConvertVideoOperation::VideoConversionDone( TInt aStatus )
       
   302     {
       
   303     switch ( aStatus )
       
   304         {
       
   305         case KErrNone:
       
   306             {
       
   307             iOperationState = EUniConvertVidResolve;
       
   308             SetError( EUniConvertVidSuccessful );
       
   309             break;
       
   310             }
       
   311         case KErrNoMemory:
       
   312             {
       
   313             iOperationState = EUniConvertVidError;
       
   314             SetError( EUniConvertVidOutOfMemory );
       
   315             break;
       
   316             }
       
   317         case KErrDiskFull:
       
   318             {
       
   319             iOperationState = EUniConvertVidError;
       
   320             SetError( EUniConvertVidOutOfDisk );
       
   321             break;
       
   322             }
       
   323         case KErrNotFound:
       
   324             {
       
   325             iOperationState = EUniConvertVidError;
       
   326             SetError( EUniConvertVidNotFound );
       
   327             break;
       
   328             }
       
   329         default:
       
   330             {
       
   331             iOperationState = EUniConvertVidError;
       
   332             SetError( EUniConvertVidFailed );
       
   333             break;
       
   334             }
       
   335         }
       
   336     
       
   337     if ( aStatus == KErrCancel )
       
   338         {
       
   339         CompleteOperation( KErrCancel );
       
   340         }
       
   341     else
       
   342         {
       
   343         CompleteOperation( KErrNone );
       
   344         }
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------
       
   348 // CUniEditorConvertVideoOperation::CreateEmptyAttachmentL
       
   349 // ---------------------------------------------------------
       
   350 //
       
   351 void CUniEditorConvertVideoOperation::CreateEmptyAttachmentL()
       
   352     {
       
   353     iNewAttaId = KMsvNullIndexEntryId;
       
   354 
       
   355     // Get the file name from original full path name.
       
   356     TParsePtrC parser( iVideoInfo->FullFilePath() );
       
   357 
       
   358     TFileName ext( parser.Ext() );
       
   359     ext.Zero();
       
   360     ext.Copy( KUniExtVideo3gp_8 );
       
   361 
       
   362     TFileName newFileName( parser.Name() );
       
   363     newFileName.Append( ext );
       
   364 
       
   365     iEditStore = iDocument.Mtm().Entry().EditStoreL();
       
   366     MMsvAttachmentManagerSync& managerSync = iEditStore->AttachmentManagerExtensionsL();
       
   367     CMsvAttachment* attachment = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
   368     CleanupStack::PushL( attachment );
       
   369 
       
   370     attachment->SetMimeTypeL( KMsgMimeVideo3gpp );
       
   371 
       
   372     managerSync.CreateAttachmentL( newFileName, iNewVideoFile, attachment );
       
   373     
       
   374     CleanupStack::Pop( attachment ); // ownership transferred
       
   375     
       
   376     iNewAttaId = attachment->Id();
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------
       
   380 // CUniEditorConvertVideoOperation::OpenFileForReadingL
       
   381 // ---------------------------------------------------------
       
   382 //
       
   383 RFile CUniEditorConvertVideoOperation::OpenFileForReadingL()
       
   384     {
       
   385     RFile sourceFile;
       
   386     if ( iAttachmentId != KMsvNullIndexEntryId )
       
   387         {
       
   388         __ASSERT_DEBUG( iEditStore, Panic( EUniNullPointer ) );
       
   389         sourceFile = iEditStore->AttachmentManagerL().GetAttachmentFileL( iAttachmentId );
       
   390         }
       
   391     else
       
   392         {
       
   393         TInt err = sourceFile.Open( iFs, 
       
   394                                     iVideoInfo->FullFilePath(), 
       
   395                                     EFileRead | EFileShareAny );
       
   396         if ( err )
       
   397             {
       
   398             err = sourceFile.Open( iFs, 
       
   399                                    iVideoInfo->FullFilePath(), 
       
   400                                    EFileRead | EFileShareReadersOnly );
       
   401             User::LeaveIfError( err );
       
   402             }
       
   403         }
       
   404     return sourceFile;
       
   405     }
       
   406        
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CUniEditorConvertVideoOperation::DetachVideoInfo
       
   410 // ---------------------------------------------------------
       
   411 //
       
   412 CMsgVideoInfo* CUniEditorConvertVideoOperation::DetachVideoInfo()
       
   413     {
       
   414     // ownership transferred
       
   415     CMsgVideoInfo* tempInfo = iNewVideoInfo;
       
   416     iNewVideoInfo = NULL;
       
   417     return tempInfo;
       
   418     }
       
   419 
       
   420 // End of file