mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/ccopyobject.cpp
branchRCL_3
changeset 9 bee149131e4b
parent 0 a2952bb97e68
child 14 05b0d2323768
equal deleted inserted replaced
4:d45095c2f4f3 9:bee149131e4b
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Implement the operation: CopyObject
    14  * Description:  Implement the operation: CopyObject
    15 *
    15  *
    16 */
    16  */
    17 
       
    18 
    17 
    19 #include <bautils.h>
    18 #include <bautils.h>
    20 
    19 
    21 #include <mtp/mmtpdataproviderframework.h>
    20 #include <mtp/mmtpdataproviderframework.h>
    22 #include <mtp/mmtpobjectmgr.h>
    21 #include <mtp/mmtpobjectmgr.h>
    31 #include "mmmtpdplogger.h"
    30 #include "mmmtpdplogger.h"
    32 #include "tmmmtpdppanic.h"
    31 #include "tmmmtpdppanic.h"
    33 #include "mmmtpdputility.h"
    32 #include "mmmtpdputility.h"
    34 #include "mmmtpdpconfig.h"
    33 #include "mmmtpdpconfig.h"
    35 #include "cmmmtpdpmetadataaccesswrapper.h"
    34 #include "cmmmtpdpmetadataaccesswrapper.h"
       
    35 #include "cpropertysettingutility.h"
    36 
    36 
    37 /**
    37 /**
    38 * Verification data for the CopyObject request
    38  * Verification data for the CopyObject request
    39 */
    39  */
    40 const TMTPRequestElementInfo KMTPCopyObjectPolicy[] =
    40 const TMTPRequestElementInfo KMTPCopyObjectPolicy[] =
    41     {
    41     {
    42         {
    42         {
    43         TMTPTypeRequest::ERequestParameter1,
    43         TMTPTypeRequest::ERequestParameter1,
    44         EMTPElementTypeObjectHandle,
    44         EMTPElementTypeObjectHandle,
    45         EMTPElementAttrFileOrDir,
    45         EMTPElementAttrFile,
    46         0,
    46         0,
    47         0,
    47         0,
    48         0
    48         0
    49         },
    49         },
    50         {
    50         {
    73 EXPORT_C CCopyObject::~CCopyObject()
    73 EXPORT_C CCopyObject::~CCopyObject()
    74     {
    74     {
    75     Cancel();
    75     Cancel();
    76 
    76 
    77     delete iDest;
    77     delete iDest;
    78     delete iFileMan;
    78 
    79     iObjectHandles.Close();
       
    80     if ( iPropertyElement )
    79     if ( iPropertyElement )
    81         delete iPropertyElement;
    80         delete iPropertyElement;
    82     delete iPropertyList;
    81     delete iPropertyList;
    83     delete iPathToCopy;
       
    84     delete iNewRootFolder;
       
    85     }
    82     }
    86 
    83 
    87 // -----------------------------------------------------------------------------
    84 // -----------------------------------------------------------------------------
    88 // CCopyObject::CCopyObject
    85 // CCopyObject::CCopyObject
    89 // Standard c++ constructor
    86 // Standard c++ constructor
    90 // -----------------------------------------------------------------------------
    87 // -----------------------------------------------------------------------------
    91 //
    88 //
    92 EXPORT_C CCopyObject::CCopyObject( MMTPDataProviderFramework& aFramework,
    89 EXPORT_C CCopyObject::CCopyObject( MMTPDataProviderFramework& aFramework,
    93     MMTPConnection& aConnection,
    90     MMTPConnection& aConnection,
    94     MMmMtpDpConfig& aDpConfig ) :
    91     MMmMtpDpConfig& aDpConfig ) :
    95     CRequestProcessor( aFramework,
    92         CRequestProcessor( aFramework,
    96         aConnection,
    93             aConnection, 
    97         sizeof ( KMTPCopyObjectPolicy ) / sizeof(TMTPRequestElementInfo),
    94             sizeof( KMTPCopyObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
    98         KMTPCopyObjectPolicy ),
    95             KMTPCopyObjectPolicy ),
    99     iDpConfig( aDpConfig ),
    96         iDpConfig( aDpConfig )
   100     iObjectHandles( KMmMtpRArrayGranularity )
       
   101     {
    97     {
   102     PRINT( _L( "Operation: CopyObject(0x101A)" ) );
    98     PRINT( _L( "Operation: CopyObject(0x101A)" ) );
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CCopyObject::ServiceL
       
   107 // CopyObject request handler
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CCopyObject::ServiceL()
       
   111     {
       
   112     PRINT( _L( "MM MTP => CCopyObject::ServiceL" ) );
       
   113     iHandle = KMTPHandleNone;
       
   114 
       
   115     CopyObjectL( iHandle );
       
   116 
       
   117     PRINT( _L( "MM MTP <= CCopyObject::ServiceL" ) );
       
   118     }
    99     }
   119 
   100 
   120 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   121 // CCopyObject::ConstructL
   102 // CCopyObject::ConstructL
   122 // Second phase constructor
   103 // Second phase constructor
   123 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   124 //
   105 //
   125 EXPORT_C void CCopyObject::ConstructL()
   106 EXPORT_C void CCopyObject::ConstructL()
   126     {
   107     {
   127     CActiveScheduler::Add( this );
       
   128 
       
   129     iPropertyList = CMTPTypeObjectPropList::NewL();
   108     iPropertyList = CMTPTypeObjectPropList::NewL();
   130 
   109 
   131     // Set the CenRep value of MTP status,
   110     // Set the CenRep value of MTP status,
   132     // also need to do in other processors which related to MPX
   111     // also need to do in other processors which related to MPX
   133     SetPSStatus();
   112     SetPSStatus();
   134     }
   113     }
   135 
   114 
   136 // -----------------------------------------------------------------------------
   115 // -----------------------------------------------------------------------------
   137 // CCopyObject::RunL
   116 // CCopyObject::ServiceL
   138 //
   117 // CopyObject request handler
   139 // -----------------------------------------------------------------------------
   118 // -----------------------------------------------------------------------------
   140 //
   119 //
   141 EXPORT_C void CCopyObject::RunL()
   120 EXPORT_C void CCopyObject::ServiceL()
   142     {
   121     {
   143     PRINT( _L( "MM MTP => CCopyObject::RunL" ) );
   122     PRINT( _L( "MM MTP => CCopyObject::ServiceL" ) );
   144 
   123 
   145     if ( iCopyObjectIndex < iNumberOfObjects )
   124     CopyObjectL();
   146         {
   125 
   147         CopyAndUpdateL( iObjectHandles[iCopyObjectIndex++] );
   126     PRINT( _L( "MM MTP <= CCopyObject::ServiceL" ) );
   148 
       
   149         TRequestStatus* status = &iStatus;
       
   150         User::RequestComplete( status, iStatus.Int() );
       
   151         SetActive();
       
   152         }
       
   153     else
       
   154         {
       
   155         PRINT1( _L( "MM MTP <> CCopyObject::RunL iHandle = 0x%x" ), iHandle );
       
   156         SendResponseL( EMTPRespCodeOK, 1, &iHandle );
       
   157         }
       
   158 
       
   159     PRINT( _L( "MM MTP <= CCopyObject::RunL" ) );
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CCopyObject::CopyFileL
       
   164 // A helper function of CopyObjectL
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName )
       
   168     {
       
   169     const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   170     PRINT2( _L( "MM MTP => CCopyObject::CopyFileL old name = %S, aNewFileName = %S" ),
       
   171         &suid,
       
   172         &aNewFileName );
       
   173 
       
   174     GetPreviousPropertiesL( *iObjectInfo );
       
   175     User::LeaveIfError( iFileMan->Copy( suid, aNewFileName ) ); // iDest just folder
       
   176     User::LeaveIfError( iFramework.Fs().SetModified( aNewFileName, iPreviousModifiedTime ) );
       
   177     TUint32 handle = UpdateObjectInfoL( suid, aNewFileName );
       
   178 
       
   179     PRINT1( _L( "MM MTP <= CCopyObject::CopyFileL handle = 0x%x" ), handle );
       
   180 
       
   181     return handle;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CCopyObject::GenerateObjectHandleListL
       
   186 // Generate the list of handles that need to be copied to the new location
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CCopyObject::GenerateObjectHandleListL( TUint32 aParentHandle )
       
   190     {
       
   191     PRINT1( _L( "MM MTP => CCopyObject::GenerateObjectHandleListL aParentHandle = 0x%x" ),
       
   192         aParentHandle );
       
   193     RMTPObjectMgrQueryContext context;
       
   194     RArray<TUint> handles;
       
   195     CleanupClosePushL( context ); // + context
       
   196     CleanupClosePushL( handles ); // + handles
       
   197 
       
   198     TMTPObjectMgrQueryParams params( KMTPStorageAll, KMTPFormatsAll,
       
   199             aParentHandle );
       
   200     do
       
   201         {
       
   202         iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles );
       
   203 
       
   204         TInt numberOfObjects = handles.Count();
       
   205         for ( TInt i = 0; i < numberOfObjects; i++ )
       
   206             {
       
   207             if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == iFramework.DataProviderId() )
       
   208                 {
       
   209                 iObjectHandles.AppendL( handles[i] );
       
   210                 continue;
       
   211                 }
       
   212 
       
   213             // Folder
       
   214             if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == 0 ) // We know that the device dp id is always 0, otherwise the whole MTP won't work.
       
   215                 {
       
   216                 GenerateObjectHandleListL( handles[i] );
       
   217                 }
       
   218             }
       
   219         }
       
   220     while ( !context.QueryComplete() );
       
   221 
       
   222     CleanupStack::PopAndDestroy( &handles ); // - handles
       
   223     CleanupStack::PopAndDestroy( &context ); // - context
       
   224     PRINT( _L( "MM MTP <= CCopyObject::GenerateObjectHandleListL" ) );
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CCopyObject::CopyFolderL
       
   229 // A helper function of CopyObjectL
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 TUint32 CCopyObject::CopyFolderL( const TDesC& aNewFolderName )
       
   233     {
       
   234     PRINT1( _L( "MM MTP => CCopyObject::CopyFolderL aNewFolderName = %S" ), &aNewFolderName );
       
   235     TUint32 handle = iFramework.ObjectMgr().HandleL( aNewFolderName ); // just get it
       
   236 
       
   237     GenerateObjectHandleListL( iObjectInfo->Uint( CMTPObjectMetaData::EHandle ) );
       
   238     iCopyObjectIndex = 0;
       
   239     iNumberOfObjects = iObjectHandles.Count();
       
   240     PRINT1( _L( "MM MTP <> CCopyObject::CopyFolderL iNumberOfObjects = %d" ), iNumberOfObjects );
       
   241 
       
   242     TRequestStatus* status = &iStatus;
       
   243     User::RequestComplete( status, iStatus.Int() );
       
   244     SetActive();
       
   245 
       
   246     PRINT1( _L( "MM MTP <= CCopyObject::CopyFolderL handle = 0x%x" ), handle );
       
   247     return handle;
       
   248     }
   127     }
   249 
   128 
   250 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   251 // CCopyObject::CopyObjectL
   130 // CCopyObject::CopyObjectL
   252 // Copy object operation
   131 // Copy object operation
   253 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   254 //
   133 //
   255 void CCopyObject::CopyObjectL( TUint32& aNewHandle )
   134 void CCopyObject::CopyObjectL()
   256     {
   135     {
   257     PRINT( _L( "MM MTP => CCopyObject::CopyObjectL" ) );
   136     PRINT( _L( "MM MTP => CCopyObject::CopyObjectL" ) );
       
   137 
   258     TMTPResponseCode responseCode = EMTPRespCodeOK;
   138     TMTPResponseCode responseCode = EMTPRespCodeOK;
   259     aNewHandle = KMTPHandleNone;
       
   260 
   139 
   261     GetParametersL();
   140     GetParametersL();
   262 
   141 
   263     RBuf newObjectName;
   142     RBuf newObjectName;
       
   143     newObjectName.CreateL( KMaxFileName );
   264     newObjectName.CleanupClosePushL(); // + newObjectName
   144     newObjectName.CleanupClosePushL(); // + newObjectName
   265     newObjectName.CreateL( KMaxFileName );
       
   266     newObjectName = *iDest;
   145     newObjectName = *iDest;
   267 
   146 
   268     const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   147     const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   269     TParsePtrC fileNameParser( suid );
   148     TParsePtrC fileNameParser( suid );
   270 
   149     if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() )
   271     // Check if the object is a folder or a file.
   150         <= newObjectName.MaxLength() )
   272     TBool isFolder = EFalse;
   151         {
   273     User::LeaveIfError( BaflUtils::IsFolder( iFramework.Fs(), suid, isFolder ) );
   152         newObjectName.Append( fileNameParser.NameAndExt() );
   274 
   153         }
   275     if ( !isFolder )
   154     responseCode = CanCopyObjectL( suid, newObjectName );
   276         {
   155 
   277         if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() ) <= newObjectName.MaxLength() )
   156     TUint32 newHandle = KMTPHandleNone;
   278             {
       
   279             newObjectName.Append( fileNameParser.NameAndExt() );
       
   280             }
       
   281         responseCode = CanCopyObjectL( suid, newObjectName );
       
   282         }
       
   283     else // It is a folder.
       
   284         {
       
   285         TFileName rightMostFolderName;
       
   286         User::LeaveIfError( BaflUtils::MostSignificantPartOfFullName( suid,
       
   287             rightMostFolderName ) );
       
   288         if ( ( newObjectName.Length() + rightMostFolderName.Length() + 1 ) <= newObjectName.MaxLength() )
       
   289             {
       
   290             newObjectName.Append( rightMostFolderName );
       
   291             // Add backslash.
       
   292             _LIT( KBackSlash, "\\" );
       
   293             newObjectName.Append( KBackSlash );
       
   294             }
       
   295         }
       
   296 
       
   297     delete iNewRootFolder;
       
   298     iNewRootFolder = NULL;
       
   299     iNewRootFolder = newObjectName.AllocL();
       
   300 
       
   301     if ( responseCode == EMTPRespCodeOK )
   157     if ( responseCode == EMTPRespCodeOK )
   302         {
   158         {
   303         delete iFileMan;
   159         newHandle = CopyFileL( newObjectName );
   304         iFileMan = NULL;
   160         SendResponseL( EMTPRespCodeOK, 1, &newHandle );
   305         iFileMan = CFileMan::NewL( iFramework.Fs() );
       
   306 
       
   307         if ( !isFolder ) // It is a file.
       
   308             {
       
   309             aNewHandle = CopyFileL( newObjectName );
       
   310 //            if ( responseCode == EMTPRespCodeOK  )
       
   311             SendResponseL( EMTPRespCodeOK, 1, &aNewHandle );
       
   312 //            else
       
   313 //                SendResponseL( responseCode );
       
   314             }
       
   315         else // It is a folder.
       
   316             {
       
   317             delete iPathToCopy;
       
   318             iPathToCopy = NULL;
       
   319             iPathToCopy = suid.AllocL();
       
   320             PRINT1( _L( "MM MTP <> CCopyObject::CopyObjectL iPathToCopy = %S" ), iPathToCopy );
       
   321             aNewHandle = CopyFolderL( newObjectName );
       
   322             }
       
   323         }
   161         }
   324     else
   162     else
   325         SendResponseL( responseCode );
   163         SendResponseL( responseCode );
   326 
   164 
   327     CleanupStack::PopAndDestroy( &newObjectName ); // - newObjectName
   165     CleanupStack::PopAndDestroy( &newObjectName ); // - newObjectName
   328     PRINT2( _L( "MM MTP <= CCopyObject::CopyObjectL responseCode = 0x%x, aNewHandle = 0x%x" ),
   166     PRINT2( _L( "MM MTP <= CCopyObject::CopyObjectL responseCode = 0x%x, aNewHandle = 0x%x" ),
   329             responseCode, aNewHandle );
   167         responseCode,
       
   168         newHandle );
   330     }
   169     }
   331 
   170 
   332 // -----------------------------------------------------------------------------
   171 // -----------------------------------------------------------------------------
   333 // CCopyObject::GetParametersL
   172 // CCopyObject::GetParametersL
   334 // Retrieve the parameters of the request
   173 // Retrieve the parameters of the request
   335 // -----------------------------------------------------------------------------
   174 // -----------------------------------------------------------------------------
   336 //
   175 //
   337 void CCopyObject::GetParametersL()
   176 void CCopyObject::GetParametersL()
   338     {
   177     {
   339     PRINT( _L( "MM MTP => CCopyObject::GetParametersL" ) );
   178     PRINT( _L( "MM MTP => CCopyObject::GetParametersL" ) );
       
   179 
   340     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   180     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   341 
   181 
   342     TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   182     TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   343     iStorageId = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   183     iStorageId = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   344     TUint32 parentObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   184     iNewParentHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   345     PRINT3( _L( "MM MTP <> CCopyObject::GetParametersL Object Hanlde = 0x%x, StorageId = 0x%x, Parent Handle = 0x%x" ),
   185     PRINT3( _L( "MM MTP <> CCopyObject::GetParametersL Object Handle = 0x%x, StorageId = 0x%x, Parent Handle = 0x%x" ),
   346             objectHandle, iStorageId, parentObjectHandle );
   186         objectHandle,
       
   187         iStorageId,
       
   188         iNewParentHandle );
   347 
   189 
   348     // not taking owernship
   190     // not taking owernship
   349     iObjectInfo = iRequestChecker->GetObjectInfo( objectHandle );
   191     iObjectInfo = iRequestChecker->GetObjectInfo( objectHandle );
   350     __ASSERT_DEBUG( iObjectInfo, Panic( EMmMTPDpObjectNull ) );
   192     __ASSERT_DEBUG( iObjectInfo, Panic( EMmMTPDpObjectNull ) );
   351 
   193 
   352     if ( parentObjectHandle == 0 )
   194     if ( iNewParentHandle == KMTPHandleNone )
   353         {
   195         {
   354         SetDefaultParentObjectL();
   196         SetDefaultParentObjectL();
   355         }
   197         }
   356     else
   198     else
   357         {
   199         {
   358         CMTPObjectMetaData* parentObjectInfo = iRequestChecker->GetObjectInfo( parentObjectHandle );
   200         CMTPObjectMetaData* parentObject = iRequestChecker->GetObjectInfo( iNewParentHandle );
   359         __ASSERT_DEBUG( parentObjectInfo, Panic( EMmMTPDpObjectNull ) );
   201         __ASSERT_DEBUG( parentObject, Panic( EMmMTPDpObjectNull ) );
       
   202 
   360         delete iDest;
   203         delete iDest;
   361         iDest = NULL;
   204         iDest = NULL;
   362         iDest = parentObjectInfo->DesC( CMTPObjectMetaData::ESuid ).AllocL();
   205         iDest = parentObject->DesC( CMTPObjectMetaData::ESuid ).AllocL();
   363         iNewParentHandle = parentObjectHandle;
   206         PRINT1( _L( "MM MTP <> CMoveObject::GetParametersL iDest = %S" ), iDest );
   364         }
   207         }
   365     PRINT( _L( "MM MTP <= CCopyObject::GetParametersL" ) );
   208     PRINT( _L( "MM MTP <= CCopyObject::GetParametersL" ) );
   366     }
   209     }
   367 
   210 
   368 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   374     {
   217     {
   375     PRINT( _L( "MM MTP => CCopyObject::SetDefaultParentObjectL" ) );
   218     PRINT( _L( "MM MTP => CCopyObject::SetDefaultParentObjectL" ) );
   376 
   219 
   377     delete iDest;
   220     delete iDest;
   378     iDest = NULL;
   221     iDest = NULL;
   379     iDest = ( iFramework.StorageMgr().StorageL( iStorageId ).DesC(
   222     iDest = iFramework.StorageMgr().StorageL( iStorageId ).DesC( CMTPStorageMetaData::EStorageSuid ).AllocL();
   380                 CMTPStorageMetaData::EStorageSuid ) ).AllocL();
   223 
   381     PRINT1( _L( "MM MTP <> CCopyObject::SetDefaultParentObjectL Destination location is %S" ), iDest );
       
   382     iNewParentHandle = KMTPHandleNoParent;
   224     iNewParentHandle = KMTPHandleNoParent;
   383     PRINT( _L( "MM MTP <= CCopyObject::SetDefaultParentObjectL" ) );
   225 
       
   226     PRINT1( _L( "MM MTP <= CCopyObject::SetDefaultParentObjectL, iDest = %S" ), iDest );
   384     }
   227     }
   385 
   228 
   386 // -----------------------------------------------------------------------------
   229 // -----------------------------------------------------------------------------
   387 // CCopyObject::CanCopyObjectL
   230 // CCopyObject::CanCopyObjectL
   388 // Check if we can copy the file to the new location
   231 // Check if we can copy the file to the new location
   390 //
   233 //
   391 TMTPResponseCode CCopyObject::CanCopyObjectL( const TDesC& aOldName,
   234 TMTPResponseCode CCopyObject::CanCopyObjectL( const TDesC& aOldName,
   392     const TDesC& aNewName ) const
   235     const TDesC& aNewName ) const
   393     {
   236     {
   394     PRINT2( _L( "MM MTP => CCopyObject::CanCopyObjectL aOldName = %S, aNewName = %S" ),
   237     PRINT2( _L( "MM MTP => CCopyObject::CanCopyObjectL aOldName = %S, aNewName = %S" ),
   395             &aOldName, &aNewName );
   238         &aOldName,
       
   239         &aNewName );
   396     TMTPResponseCode result = EMTPRespCodeOK;
   240     TMTPResponseCode result = EMTPRespCodeOK;
   397 
   241 
   398     TEntry fileEntry;
   242     TEntry fileEntry;
   399     User::LeaveIfError( iFramework.Fs().Entry( aOldName, fileEntry ) );
   243     User::LeaveIfError( iFramework.Fs().Entry( aOldName, fileEntry ) );
   400     TDriveNumber drive( static_cast<TDriveNumber>( iFramework.StorageMgr().DriveNumber( iStorageId ) ) );
   244     TInt drive = iFramework.StorageMgr().DriveNumber( iStorageId );
   401     User::LeaveIfError( drive );
   245     User::LeaveIfError( drive );
   402     TVolumeInfo volumeInfo;
   246     TVolumeInfo volumeInfo;
   403     User::LeaveIfError( iFramework.Fs().Volume( volumeInfo, drive ) );
   247     User::LeaveIfError( iFramework.Fs().Volume( volumeInfo, drive ) );
   404 
   248 
   405     if ( volumeInfo.iFree < fileEntry.iSize )
   249     if ( volumeInfo.iFree < fileEntry.FileSize() )
   406         {
   250         {
   407         result = EMTPRespCodeStoreFull;
   251         result = EMTPRespCodeStoreFull;
   408         }
   252         }
   409     else if ( BaflUtils::FileExists( iFramework.Fs(), aNewName ) )
   253     else if ( BaflUtils::FileExists( iFramework.Fs(), aNewName ) )
   410         {
   254         {
   443     PRINT1( _L( "MM MTP <= CCopyObject::CanCopyObjectL result = 0x%x" ), result );
   287     PRINT1( _L( "MM MTP <= CCopyObject::CanCopyObjectL result = 0x%x" ), result );
   444     return result;
   288     return result;
   445     }
   289     }
   446 
   290 
   447 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
       
   292 // CCopyObject::CopyFileL
       
   293 // A helper function of CopyFileL
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName )
       
   297     {
       
   298     const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   299     PRINT2( _L( "MM MTP => CCopyObject::CopyFileL old name = %S, aNewFileName = %S" ),
       
   300         &suid,
       
   301         &aNewFileName );
       
   302 
       
   303     GetPreviousPropertiesL( *iObjectInfo );
       
   304 
       
   305     TUint32 handle = AddObjectToStoreL( suid, aNewFileName );
       
   306 
       
   307     SetPreviousPropertiesL( *iObjectInfo );
       
   308 
       
   309     CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() );
       
   310     User::LeaveIfError( fileMan->Copy( suid, aNewFileName ) );
       
   311     delete fileMan;
       
   312     fileMan = NULL;
       
   313 
       
   314     User::LeaveIfError( iFramework.Fs().SetModified( aNewFileName,
       
   315         iPreviousModifiedTime ) );
       
   316 
       
   317     PRINT1( _L( "MM MTP <= CCopyObject::CopyFileL handle = 0x%x" ), handle );
       
   318 
       
   319     return handle;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
   448 // CCopyObject::GetPreviousPropertiesL
   323 // CCopyObject::GetPreviousPropertiesL
   449 // Save the object properties before doing the copy
   324 // Save the object properties before doing the copy
   450 // -----------------------------------------------------------------------------
   325 // -----------------------------------------------------------------------------
   451 //
   326 //
   452 void CCopyObject::GetPreviousPropertiesL( const CMTPObjectMetaData& aObject )
   327 void CCopyObject::GetPreviousPropertiesL( const CMTPObjectMetaData& aObject )
   453     {
   328     {
   454     PRINT( _L( "MM MTP => CCopyObject::GetPreviousPropertiesL" ) );
   329     PRINT( _L( "MM MTP => CCopyObject::GetPreviousPropertiesL" ) );
   455 
   330 
   456     const TDesC& suid( aObject.DesC( CMTPObjectMetaData::ESuid ) );
   331     const TDesC& suid( aObject.DesC( CMTPObjectMetaData::ESuid ) );
   457 
       
   458     User::LeaveIfError( iFramework.Fs().Modified( suid, iPreviousModifiedTime ) );
   332     User::LeaveIfError( iFramework.Fs().Modified( suid, iPreviousModifiedTime ) );
   459 
   333 
   460     TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode );
   334     TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode );
   461     const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode );
   335     const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode );
   462     TInt count = properties->Count();
   336     TInt count = properties->Count();
   463 
   337 
   464     CMTPTypeString* textData = NULL;
       
   465     TInt err = KErrNone;
   338     TInt err = KErrNone;
   466     TUint16 propCode;
   339     TUint16 propCode;
   467     TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle ) ;
   340     TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle );
   468 
   341 
   469     if ( iPropertyElement )
   342     if ( iPropertyElement != NULL )
   470         {
   343         {
   471         delete iPropertyElement;
   344         delete iPropertyElement;
   472         iPropertyElement = NULL;
   345         iPropertyElement = NULL;
   473         }
   346         }
   474     
   347 
   475     for ( TInt i = 0; i < count; i++ )
   348     for ( TInt i = 0; i < count; i++ )
   476         {
   349         {
   477         propCode = (*properties)[i];
   350         propCode = ( *properties )[i];
   478 
   351 
   479         switch( propCode )
   352         switch ( propCode )
   480             {
   353             {
   481             case EMTPObjectPropCodeStorageID:
   354             case EMTPObjectPropCodeStorageID:
   482             case EMTPObjectPropCodeObjectFormat:
   355             case EMTPObjectPropCodeObjectFormat:
   483             case EMTPObjectPropCodeProtectionStatus:
   356             case EMTPObjectPropCodeProtectionStatus:
   484             case EMTPObjectPropCodeObjectSize:
   357             case EMTPObjectPropCodeObjectSize:
   485             case EMTPObjectPropCodeObjectFileName:
   358             case EMTPObjectPropCodeObjectFileName:
   486             case EMTPObjectPropCodeParentObject:
   359             case EMTPObjectPropCodeParentObject:
   487             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   360             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   488             case EMTPObjectPropCodeNonConsumable:
       
   489             case EMTPObjectPropCodeDateCreated:
   361             case EMTPObjectPropCodeDateCreated:
   490             case EMTPObjectPropCodeDateModified:
   362             case EMTPObjectPropCodeDateModified:
       
   363                 break;
       
   364 
       
   365             case EMTPObjectPropCodeNonConsumable:
       
   366                 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) );
       
   367                 iPropertyElement->SetUint8L( CMTPTypeObjectPropListElement::EValue,
       
   368                     aObject.Uint( CMTPObjectMetaData::ENonConsumable ) );
   491                 break;
   369                 break;
   492 
   370 
   493             case EMTPObjectPropCodeName:
   371             case EMTPObjectPropCodeName:
   494             case EMTPObjectPropCodeDateAdded:
   372             case EMTPObjectPropCodeDateAdded:
   495                 if ( ( propCode == EMTPObjectPropCodeName )
   373                 if ( ( propCode == EMTPObjectPropCodeName )
   496                    || ( ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework ) )
   374                     || ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework )
   497                         && ( propCode == EMTPObjectPropCodeDateAdded ) ) )
   375                         && ( propCode == EMTPObjectPropCodeDateAdded ) ) )
   498                     {
   376                     {
   499                     textData = CMTPTypeString::NewLC(); // + textData
   377                     CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData
   500 
   378 
   501                     TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode,
   379                     TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode,
   502                         *textData,
   380                         *textData,
   503                         aObject ) );
   381                         aObject ) );
   504 
   382 
   505                     PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL::ServiceSpecificObjectPropertyL err = %d" ), err );
   383                     PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL err = %d" ), err );
   506 
   384 
   507                     if ( err == KErrNone )
   385                     if ( err == KErrNone )
   508                         {
   386                         {
   509                         iPropertyElement = &(iPropertyList->ReservePropElemL(handle, propCode));
   387                         iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) );
   510                         iPropertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, textData->StringChars());
   388                         iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue,
   511 //                        iPropertyElement = CMTPTypeObjectPropListElement::NewL(
   389                             textData->StringChars() );
   512 //                                handle, propCode, *textData );
       
   513                         }
   390                         }
   514                     else if ( err == KErrNotFound )
   391                     else if ( err == KErrNotFound )
   515                         {
   392                         {
   516                         iPropertyElement = NULL;
   393                         iPropertyElement = NULL;
   517                         }
   394                         }
   529                 ServiceGetSpecificObjectPropertyL( propCode, handle, aObject );
   406                 ServiceGetSpecificObjectPropertyL( propCode, handle, aObject );
   530                 }
   407                 }
   531                 break;
   408                 break;
   532             }
   409             }
   533 
   410 
   534         if ( iPropertyElement )
   411         if ( iPropertyElement != NULL )
   535             {
   412             {
   536             iPropertyList->CommitPropElemL( *iPropertyElement );
   413             iPropertyList->CommitPropElemL( *iPropertyElement );
   537             iPropertyElement = NULL;
   414             iPropertyElement = NULL;
   538             }
   415             }
   539         } // end of for loop
   416         } // end of for loop
   540 
   417 
   541     PRINT1( _L( "MM MTP <= CCopyObject::GetPreviousPropertiesL err = %d" ), err );
   418     PRINT1( _L( "MM MTP <= CCopyObject::GetPreviousPropertiesL err = %d" ), err );
   542     }
   419     }
   543 
   420 
   544 // -----------------------------------------------------------------------------
   421 // -----------------------------------------------------------------------------
   545 // CCopyObject::ServiceMetaDataToWrapper
       
   546 //
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 EXPORT_C TMTPResponseCode CCopyObject::ServiceMetaDataToWrapper(
       
   550     const TUint16 aPropCode,
       
   551     MMTPType& aNewData,
       
   552     const CMTPObjectMetaData& aObject )
       
   553     {
       
   554     TMTPResponseCode resCode = EMTPRespCodeOK;
       
   555 
       
   556     TRAPD( err, iDpConfig.GetWrapperL().SetObjectMetadataValueL( aPropCode,
       
   557         aNewData,
       
   558         aObject ) );
       
   559 
       
   560     PRINT1( _L("MM MTP <> CCopyObject::ServiceMetaDataToWrapper err = %d"), err);
       
   561 
       
   562     if ( err == KErrNone )
       
   563         {
       
   564         resCode = EMTPRespCodeOK;
       
   565         }
       
   566     else if ( err == KErrTooBig )
       
   567         // according to the codes of S60
       
   568         {
       
   569         resCode = EMTPRespCodeInvalidDataset;
       
   570         }
       
   571     else if ( err == KErrPermissionDenied )
       
   572         {
       
   573         resCode = EMTPRespCodeAccessDenied;
       
   574         }
       
   575     else if ( err == KErrNotFound )
       
   576         {
       
   577         if ( MmMtpDpUtility::HasMetadata( aObject.Uint( CMTPObjectMetaData::EFormatCode ) ) )
       
   578             resCode = EMTPRespCodeAccessDenied;
       
   579         else
       
   580             resCode = EMTPRespCodeOK;
       
   581         }
       
   582     else
       
   583         {
       
   584         resCode = EMTPRespCodeGeneralError;
       
   585         }
       
   586 
       
   587     PRINT1( _L("MM MTP <= CCopyObject::ServiceMetaDataToWrapper resCode = 0x%x"), resCode);
       
   588 
       
   589     return resCode;
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CCopyObject::SetPreviousPropertiesL
   422 // CCopyObject::SetPreviousPropertiesL
   594 // Set the object properties after doing the copy
   423 // Set the object properties after doing the copy
   595 // -----------------------------------------------------------------------------
   424 // -----------------------------------------------------------------------------
   596 //
   425 //
   597 void CCopyObject::SetPreviousPropertiesL( const CMTPObjectMetaData& aObject )
   426 void CCopyObject::SetPreviousPropertiesL( const CMTPObjectMetaData& aObject )
   598     {
   427     {
   599     PRINT( _L( "MM MTP => CCopyObject::SetPreviousPropertiesL" ) );
   428     PRINT( _L( "MM MTP => CCopyObject::SetPreviousPropertiesL" ) );
   600     const TInt count( iPropertyList->NumberOfElements() );
   429 
   601     PRINT1( _L( "MM MTP <> CCopyObject::SetPreviousPropertiesL count = %d" ), count );
       
   602     TMTPResponseCode respcode = EMTPRespCodeOK;
   430     TMTPResponseCode respcode = EMTPRespCodeOK;
   603     CMTPTypeString* stringData = NULL;
   431 
   604     iPropertyList->ResetCursor();
   432     iPropertyList->ResetCursor();
       
   433     const TInt count = iPropertyList->NumberOfElements();
   605     for ( TInt i = 0; i < count; i++ )
   434     for ( TInt i = 0; i < count; i++ )
   606         {
   435         {
   607         CMTPTypeObjectPropListElement& element = iPropertyList->GetNextElementL();
   436         CMTPTypeObjectPropListElement& element = iPropertyList->GetNextElementL();
   608 
   437 
   609         TUint32 handle = element.Uint32L(
   438         TUint32 handle = element.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle );
   610                 CMTPTypeObjectPropListElement::EObjectHandle );
   439         TUint16 propertyCode = element.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
   611         TUint16 propertyCode = element.Uint16L(
   440         TUint16 dataType = element.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
   612                 CMTPTypeObjectPropListElement::EPropertyCode );
       
   613         TUint16 dataType = element.Uint16L(
       
   614                 CMTPTypeObjectPropListElement::EDatatype );
       
   615         PRINT3( _L( "MM MTP <> CCopyObject::SetPreviousPropertiesL = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
   441         PRINT3( _L( "MM MTP <> CCopyObject::SetPreviousPropertiesL = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
   616           handle, propertyCode, dataType );
   442             handle,
       
   443             propertyCode,
       
   444             dataType );
   617 
   445 
   618         switch ( propertyCode )
   446         switch ( propertyCode )
   619             {
   447             {
   620             case EMTPObjectPropCodeStorageID:
   448             case EMTPObjectPropCodeStorageID:
   621             case EMTPObjectPropCodeObjectFormat:
   449             case EMTPObjectPropCodeObjectFormat:
   622             case EMTPObjectPropCodeProtectionStatus:
   450             case EMTPObjectPropCodeProtectionStatus:
   623             case EMTPObjectPropCodeObjectSize:
   451             case EMTPObjectPropCodeObjectSize:
   624             case EMTPObjectPropCodeObjectFileName:
   452             case EMTPObjectPropCodeObjectFileName:
   625             case EMTPObjectPropCodeParentObject:
   453             case EMTPObjectPropCodeParentObject:
   626             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   454             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   627             case EMTPObjectPropCodeNonConsumable:
       
   628             case EMTPObjectPropCodeDateCreated:
   455             case EMTPObjectPropCodeDateCreated:
   629             case EMTPObjectPropCodeDateModified:
   456             case EMTPObjectPropCodeDateModified:
   630             case EMTPObjectPropCodeDateAdded:
   457             case EMTPObjectPropCodeDateAdded:
   631                 break;
   458                 break;
   632 
   459 
       
   460             case EMTPObjectPropCodeNonConsumable:
       
   461                 iObjectInfo->SetUint( CMTPObjectMetaData::ENonConsumable,
       
   462                     element.Uint8L( CMTPTypeObjectPropListElement::EValue ) );
       
   463                 // TODO: need to reconsider,
       
   464                 // should wait all property setting finished then insert object, or not?
       
   465                 // need to investigate if it will affect performance result
       
   466                 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo );
       
   467                 break;
       
   468 
   633             case EMTPObjectPropCodeName:
   469             case EMTPObjectPropCodeName:
   634                 {
   470                 {
   635                 stringData = CMTPTypeString::NewLC(
   471                 CMTPTypeString *stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) ); // + stringData
   636                     element.StringL(
   472 
   637                     CMTPTypeObjectPropListElement::EValue)); // + stringData
   473                 respcode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapperL( iDpConfig,
   638 
   474                     propertyCode,
   639                 respcode = ServiceMetaDataToWrapper( propertyCode,
       
   640                     *stringData,
   475                     *stringData,
   641                     aObject );
   476                     aObject );
   642 
   477 
   643                 CleanupStack::PopAndDestroy( stringData ); // - stringData
   478                 CleanupStack::PopAndDestroy( stringData ); // - stringData
   644                 }
   479                 }
   645                 break;
   480                 break;
   646 
   481 
   647             default:
   482             default:
   648                 {
   483                 {
   649                 respcode = ServiceSetSpecificObjectPropertyL( propertyCode,
   484                 respcode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig,
   650                         aObject,
   485                     propertyCode,
   651                         element );
   486                     aObject,
       
   487                     element );
   652                 }
   488                 }
   653                 break;
   489                 break;
   654             }
   490             }
   655         } // end of for loop
   491         } // end of for loop
   656 
   492 
   657     if( respcode == EMTPRespCodeOK )
   493     // ignore errors
   658         {
       
   659         // do nothing, ignore warning
       
   660         }
       
   661 
   494 
   662     PRINT1( _L( "MM MTP <= CCopyObject::SetPreviousPropertiesL respcode = 0x%x" ), respcode );
   495     PRINT1( _L( "MM MTP <= CCopyObject::SetPreviousPropertiesL respcode = 0x%x" ), respcode );
   663     }
   496     }
   664 
   497 
   665 // -----------------------------------------------------------------------------
   498 // -----------------------------------------------------------------------------
   666 // CCopyObject::UpdateObjectInfoL
   499 // CCopyObject::UpdateObjectInfoL
   667 // Update object info in the database
   500 // Update object info in the database
   668 // -----------------------------------------------------------------------------
   501 // -----------------------------------------------------------------------------
   669 //
   502 //
   670 TUint32 CCopyObject::UpdateObjectInfoL( const TDesC& aOldObjectName, const TDesC& aNewObjectName )
   503 TUint32 CCopyObject::AddObjectToStoreL( const TDesC& aOldObjectName,
   671     {
   504     const TDesC& aNewObjectName )
   672     PRINT2( _L( "MM MTP => CCopyObject::UpdateObjectInfoL aOldObjectName = %S, aNewObjectName = %S" ),
   505     {
   673             &aOldObjectName, &aNewObjectName );
   506     PRINT2( _L( "MM MTP => CCopyObject::AddObjectToStoreL aOldObjectName = %S, aNewObjectName = %S" ),
   674     // We should not modify this object's handle, so just get a "copy".
   507         &aOldObjectName,
       
   508         &aNewObjectName );
       
   509 
   675     CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
   510     CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
   676     const TMTPTypeUint32 objectHandle( iObjectInfo->Uint( CMTPObjectMetaData::EHandle ) );
   511 
   677     if ( iFramework.ObjectMgr().ObjectL( objectHandle, *objectInfo) )
   512     // 1. Add new object into objectMgr db
   678         {
   513     objectInfo->SetUint( CMTPObjectMetaData::EDataProviderId, iObjectInfo->Uint( CMTPObjectMetaData::EDataProviderId ) );
   679         objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName );
   514     TUint formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode );
   680         objectInfo->SetUint( CMTPObjectMetaData::EParentHandle,
   515     objectInfo->SetUint( CMTPObjectMetaData::EFormatCode, formatCode );
   681                 iNewParentHandle );
   516     TUint subFormatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatSubCode );
   682         // Modify storage Id.
   517     objectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, subFormatCode );
   683         objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
   518     objectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle );
   684         iFramework.ObjectMgr().InsertObjectL( *objectInfo );
   519     objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
   685         }
   520     objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName );
   686     else
   521     iFramework.ObjectMgr().InsertObjectL( *objectInfo );
   687         {
   522 
   688         User::Leave( KErrCorrupt );
   523     // 2. Add new object into MPX db
       
   524     iDpConfig.GetWrapperL().AddObjectL( aNewObjectName, formatCode, subFormatCode );
       
   525 
       
   526     // 3. Set references into references db
       
   527     if ( formatCode == EMTPFormatCodeM3UPlaylist )
       
   528         {
       
   529         MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
       
   530         CDesCArray* references = referenceMgr.ReferencesLC( aOldObjectName ); // + references
       
   531         referenceMgr.SetReferencesL( aNewObjectName, *references );
       
   532         CleanupStack::PopAndDestroy( references ); // - references
   689         }
   533         }
   690 
   534 
   691     TUint32 handle = objectInfo->Uint( CMTPObjectMetaData::EHandle );
   535     TUint32 handle = objectInfo->Uint( CMTPObjectMetaData::EHandle );
   692     PRINT1( _L( "MM MTP <> CCopyObject::UpdateObjectInfoL handle = 0x%x" ), handle );
       
   693     SetPropertiesL( aOldObjectName, aNewObjectName, *objectInfo );
       
   694     CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
   536     CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
   695     PRINT( _L( "MM MTP <= CCopyObject::UpdateObjectInfoL" ) );
   537 
       
   538     PRINT1( _L( "MM MTP <= CCopyObject::AddObjectToStoreL handle = 0x%x" ), handle );
   696     return handle;
   539     return handle;
   697     }
   540     }
   698 
   541 
   699 // -----------------------------------------------------------------------------
       
   700 // CCopyObject::CopyAndUpdateL
       
   701 // Move a single object and update the database
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CCopyObject::CopyAndUpdateL( TUint32 aObjectHandle )
       
   705     {
       
   706     PRINT1( _L( "MM MTP => CopyObject::CopyAndUpdateL aObjectHanlde = 0x%x" ), aObjectHandle );
       
   707     CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
       
   708 
       
   709     if ( iFramework.ObjectMgr().ObjectL( aObjectHandle, *objectInfo ) )
       
   710         {
       
   711         // This is used to keep the same behavior in mass storage and device file manager.
       
   712         if ( objectInfo->Uint( CMTPObjectMetaData::EFormatCode )
       
   713             == EMTPFormatCodeAbstractAudioVideoPlaylist )
       
   714             {
       
   715             PRINT( _L( "MM MTP <> CopyObject::CopyAndUpdateL Playlist file don't to be copieds" ) );
       
   716             CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
       
   717             return;
       
   718             }
       
   719 
       
   720         RBuf fileName; // This is the source object name.
       
   721         fileName.CleanupClosePushL(); // + fileName
       
   722         fileName.CreateL( KMaxFileName );
       
   723 
       
   724         RBuf oldFileName;
       
   725         oldFileName.CleanupClosePushL(); // + oldFileName
       
   726         oldFileName.CreateL( KMaxFileName );
       
   727 
       
   728         RBuf rightPartName;
       
   729         rightPartName.CleanupClosePushL(); // + rightPartName
       
   730         rightPartName.CreateL( KMaxFileName );
       
   731 
       
   732         fileName = objectInfo->DesC( CMTPObjectMetaData::ESuid );
       
   733         oldFileName = fileName;
       
   734 
       
   735         rightPartName = fileName.Right( fileName.Length()
       
   736             - iPathToCopy->Length() );
       
   737 
       
   738         if ( ( iNewRootFolder->Length() + rightPartName.Length() ) > fileName.MaxLength() )
       
   739             {
       
   740             User::Leave( KErrCorrupt );
       
   741             }
       
   742 
       
   743         fileName.Zero();
       
   744         fileName.Append( *iNewRootFolder );
       
   745         fileName.Append( rightPartName );
       
   746         PRINT1( _L( "MM MTP <> CopyAndUpdateL fileName = %S" ), &fileName );
       
   747 
       
   748         if ( objectInfo->Uint( CMTPObjectMetaData::EDataProviderId )
       
   749             == iFramework.DataProviderId() )
       
   750             {
       
   751             // should copy before the set metadata DB
       
   752             GetPreviousPropertiesL( *objectInfo );
       
   753             TInt err = iFileMan->Copy( oldFileName, fileName );
       
   754             PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL err = %d" ), err );
       
   755             User::LeaveIfError( err );
       
   756             User::LeaveIfError( iFramework.Fs().SetModified( fileName,
       
   757                 iPreviousModifiedTime ) );
       
   758 
       
   759             // Modify Suid
       
   760             objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, fileName );
       
   761 
       
   762             // Modify parentHandle
       
   763             TParsePtrC parentSuid( fileName );
       
   764             PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL parentSuid = %S" ), &(parentSuid.DriveAndPath()) );
       
   765 
       
   766             TUint32 parentHandle = iFramework.ObjectMgr().HandleL( parentSuid.DriveAndPath() );
       
   767             objectInfo->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
       
   768             PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL parentHandle = 0x%x" ), parentHandle );
       
   769 
       
   770             // Modify storage Id.
       
   771             objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
       
   772             TRAP( err, iFramework.ObjectMgr().InsertObjectL( *objectInfo ) );
       
   773             if ( err != KErrNone )
       
   774                 PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL err = %d" ), err );
       
   775             // Set the properties of the new object
       
   776             SetPropertiesL( oldFileName, fileName, *objectInfo );
       
   777             }
       
   778         // Else this is not the owner of this object, so don't update the object store.
       
   779 
       
   780         CleanupStack::PopAndDestroy( &rightPartName ); // - rightPartName
       
   781         CleanupStack::PopAndDestroy( &oldFileName ); // - oldFileName
       
   782         CleanupStack::PopAndDestroy( &fileName ); // - fileName
       
   783         }
       
   784     else
       
   785         {
       
   786         User::Leave( KErrCorrupt );
       
   787         }
       
   788 
       
   789     CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
       
   790 
       
   791     PRINT( _L( "MM MTP <= CopyObject::CopyAndUpdateL" ) );
       
   792     }
       
   793 
       
   794 // -----------------------------------------------------------------------------
       
   795 // CCopyObject::SetPropertiesL
       
   796 // Set the object properties in the object property store
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 void CCopyObject::SetPropertiesL( const TDesC& aOldFileName,
       
   800         const TDesC& aNewFileName,
       
   801         const CMTPObjectMetaData& aObject )
       
   802     {
       
   803     PRINT( _L( "MM MTP => CCopyObject::SetPropertiesL" ) );
       
   804     // won't leave with KErrAlreadyExist
       
   805     iDpConfig.GetWrapperL().AddObjectL( aNewFileName );
       
   806 
       
   807     TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode );
       
   808     if ( formatCode == EMTPFormatCodeM3UPlaylist )
       
   809         {
       
   810         MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
       
   811         CDesCArray* references = referenceMgr.ReferencesLC( aOldFileName ); // + references
       
   812         referenceMgr.SetReferencesL( aNewFileName, *references );
       
   813         CleanupStack::PopAndDestroy( references ); // - references
       
   814         }
       
   815 
       
   816     SetPreviousPropertiesL( aObject );
       
   817     PRINT( _L( "MM MTP <= CCopyObject::SetPropertiesL" ) );
       
   818     }
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CCopyObject::RunError
       
   822 //
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 EXPORT_C TInt CCopyObject::RunError( TInt aError )
       
   826     {
       
   827     if ( aError != KErrNone )
       
   828         PRINT1( _L( "MM MTP <> CCopyObject::RunError aError = %d" ), aError );
       
   829 
       
   830     TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) );
       
   831     return KErrNone;
       
   832     }
       
   833 
       
   834 // end of file
   542 // end of file