mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/crenameobject.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 27 cbb1bfb7ebfb
equal deleted inserted replaced
21:a05c44bc3c61 25:d881023c13eb
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <f32file.h>
    19 #include <f32file.h>
    20 
    20 
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/mmtpobjectmgr.h>
    21 #include <mtp/mmtpobjectmgr.h>
    23 #include <mtp/cmtpobjectmetadata.h>
       
    24 #include <mtp/tmtptypeuint32.h>
    22 #include <mtp/tmtptypeuint32.h>
    25 
    23 
    26 #include "crenameobject.h"
    24 #include "crenameobject.h"
    27 #include "mmmtpdplogger.h"
    25 #include "mmmtpdplogger.h"
    28 #include "cmmmtpdpmetadataaccesswrapper.h"
    26 #include "cmmmtpdpmetadataaccesswrapper.h"
    32 // CRenameObject::NewL
    30 // CRenameObject::NewL
    33 // Two phase constructor
    31 // Two phase constructor
    34 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    35 //
    33 //
    36 EXPORT_C CRenameObject* CRenameObject::NewL( MMTPDataProviderFramework& aFramework,
    34 EXPORT_C CRenameObject* CRenameObject::NewL( MMTPDataProviderFramework& aFramework,
    37         CMmMtpDpMetadataAccessWrapper& aWrapper )
    35     CMmMtpDpMetadataAccessWrapper& aWrapper )
    38     {
    36     {
    39     PRINT( _L( "MM MTP => CRenameObject::NewL" ) );
    37     PRINT( _L( "MM MTP => CRenameObject::NewL" ) );
    40 
    38 
    41     CRenameObject* self = new ( ELeave ) CRenameObject( aFramework, aWrapper );
    39     CRenameObject* self = new ( ELeave ) CRenameObject( aFramework, aWrapper );
    42     CleanupStack::PushL( self );
    40     CleanupStack::PushL( self );
    57     CActive( EPriorityStandard ),
    55     CActive( EPriorityStandard ),
    58     iFramework( aFramework ),
    56     iFramework( aFramework ),
    59     iObjectHandles( KMmMtpRArrayGranularity ),
    57     iObjectHandles( KMmMtpRArrayGranularity ),
    60     iWrapper ( aWrapper )
    58     iWrapper ( aWrapper )
    61     {
    59     {
       
    60     // Do nothing
    62     }
    61     }
    63 
    62 
    64 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
    65 // CRenameObject::~CRenameObject
    64 // CRenameObject::~CRenameObject
    66 // destructor
    65 // destructor
   119 // Cancel the rename object process
   118 // Cancel the rename object process
   120 // -----------------------------------------------------------------------------
   119 // -----------------------------------------------------------------------------
   121 //
   120 //
   122 EXPORT_C void CRenameObject::DoCancel()
   121 EXPORT_C void CRenameObject::DoCancel()
   123     {
   122     {
   124 
   123     // Do nothing
   125     }
   124     }
   126 
   125 
   127 // -----------------------------------------------------------------------------
   126 // -----------------------------------------------------------------------------
   128 // CRenameObject::RunL
   127 // CRenameObject::RunL
   129 //
   128 //
   144             iRightPartName = iOldFileName.Right( iOldFileName.Length() - iOldFolderFullName.Length() );
   143             iRightPartName = iOldFileName.Right( iOldFileName.Length() - iOldFolderFullName.Length() );
   145             PRINT1( _L( "MM MTP <> CRenameObject::RunL right part name(%S)" ), &iRightPartName );
   144             PRINT1( _L( "MM MTP <> CRenameObject::RunL right part name(%S)" ), &iRightPartName );
   146 
   145 
   147             if ( iNewFolderName.Length() + iRightPartName.Length() <= KMaxFileName )
   146             if ( iNewFolderName.Length() + iRightPartName.Length() <= KMaxFileName )
   148                 {
   147                 {
       
   148                 PerformAdditionalActionL();
       
   149 
   149                 iFileName.Zero();
   150                 iFileName.Zero();
   150                 iFileName.Append( iNewFolderName );
   151                 iFileName.Append( iNewFolderName );
   151                 iFileName.Append( iRightPartName );
   152                 iFileName.Append( iRightPartName );
   152                 PRINT1( _L( "MM MTP <> CRenameObject::RunL new file name(%S)" ), &iFileName );
   153                 PRINT1( _L( "MM MTP <> CRenameObject::RunL new file name(%S)" ), &iFileName );
   153                 // update framework metadata DB
   154                 // update framework metadata DB
   154                 iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, iFileName );
   155                 iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, iFileName );
   155                 iObjectInfo->SetUint( CMTPObjectMetaData::EObjectMetaDataUpdate, 1 );
   156                 iObjectInfo->SetUint( CMTPObjectMetaData::EObjectMetaDataUpdate, 1 );
   156                 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo );
   157                 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo );
   157 
       
   158                 PerformAdditionalActionL();
       
   159                 }
   158                 }
   160             }
   159             }
   161 
   160 
   162         iIndex++;
   161         iIndex++;
   163 
   162 
   218     RMTPObjectMgrQueryContext context;
   217     RMTPObjectMgrQueryContext context;
   219     RArray<TUint> handles;
   218     RArray<TUint> handles;
   220     CleanupClosePushL( context ); // + context
   219     CleanupClosePushL( context ); // + context
   221     CleanupClosePushL( handles ); // + handles
   220     CleanupClosePushL( handles ); // + handles
   222 
   221 
   223     TMTPObjectMgrQueryParams params( KMTPStorageAll, KMTPFormatsAll,
   222     TMTPObjectMgrQueryParams params( KMTPStorageAll, KMTPFormatsAll, aParentHandle );
   224             aParentHandle );
       
   225     do
   223     do
   226         {
   224         {
   227         iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles );
   225         iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles );
   228 
   226 
   229         TInt numberOfObjects = handles.Count();
   227         TInt numberOfObjects = handles.Count();
   230         for ( TInt i = 0; i < numberOfObjects; i++ )
   228         for ( TInt i = 0; i < numberOfObjects; i++ )
   231             {
   229             {
   232             if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == iFramework.DataProviderId() )
   230             if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == iFramework.DataProviderId() )
   233                 {
   231                 {
   234                 iObjectHandles.AppendL( handles[i] );
   232                 iObjectHandles.AppendL( handles[i] );
   235                 continue;
   233                 // NOTE: Fw changed the mechanism of notification, no need to iterate
   236                 }
   234 
   237 
       
   238             // Folder
       
   239             // TODO: need to modify, should not know device dp id
       
   240             if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == 0 ) // We know that the device dp id is always 0, otherwise the whole MTP won't work.
       
   241                 {
       
   242                 GenerateObjectHandleListL( handles[i] );
       
   243                 }
   235                 }
   244             }
   236             }
   245         }
   237         }
   246     while ( !context.QueryComplete() );
   238     while ( !context.QueryComplete() );
   247 
   239 
   258 //
   250 //
   259 void CRenameObject::GetParentSuidL( TUint32 aHandle,
   251 void CRenameObject::GetParentSuidL( TUint32 aHandle,
   260     const TDesC& aFolderName )
   252     const TDesC& aFolderName )
   261     {
   253     {
   262     PRINT2( _L( "MM MTP => CRenameObject::GetParentSuidL aHandle(0x%x), aFolderName(%S)" ),
   254     PRINT2( _L( "MM MTP => CRenameObject::GetParentSuidL aHandle(0x%x), aFolderName(%S)" ),
   263         aHandle, &aFolderName );
   255         aHandle,
       
   256         &aFolderName );
   264     CMTPObjectMetaData* objectInfo( CMTPObjectMetaData::NewLC() ); // + objectInfo
   257     CMTPObjectMetaData* objectInfo( CMTPObjectMetaData::NewLC() ); // + objectInfo
   265     // get the old folder suid
   258     // get the old folder suid
   266     if ( iFramework .ObjectMgr().ObjectL( aHandle, *objectInfo ) )
   259     if ( iFramework .ObjectMgr().ObjectL( aHandle, *objectInfo ) )
   267         {
   260         {
   268         iNewFolderName.Zero();
   261         iNewFolderName.Zero();
   269         iNewFolderName = objectInfo->DesC( CMTPObjectMetaData::ESuid );
   262         iNewFolderName = objectInfo->DesC( CMTPObjectMetaData::ESuid );
   270         PRINT1( _L( "MM MTP <> CRenameObject::GetParentSuidL new folder full file name(%S)" ), &iNewFolderName );
   263         PRINT1( _L( "MM MTP <> CRenameObject::GetParentSuidL new folder full file name(%S)" ), &iNewFolderName );
   271         const TInt length = iNewFolderName.Length();
       
   272 
       
   273         TParsePtrC parentSuid( iNewFolderName.Left( length - 1 ) );
       
   274 
   264 
   275         iOldFolderFullName.Zero();
   265         iOldFolderFullName.Zero();
   276         iOldFolderFullName.Append( parentSuid.DriveAndPath() );
       
   277         iOldFolderFullName.Append( aFolderName ); // just name not suid
   266         iOldFolderFullName.Append( aFolderName ); // just name not suid
   278         _LIT( KBackSlash, "\\" );
   267 
   279         iOldFolderFullName.Append( KBackSlash );
       
   280         PRINT1( _L( "MM MTP <> CRenameObject::GetParentSuidL = %S" ), &iOldFolderFullName );
   268         PRINT1( _L( "MM MTP <> CRenameObject::GetParentSuidL = %S" ), &iOldFolderFullName );
   281         }
   269         }
   282     else
   270     else
   283         User::Leave( KErrCorrupt );
   271         User::Leave( KErrCorrupt );
   284 
   272 
   295 void CRenameObject::PerformAdditionalActionL()
   283 void CRenameObject::PerformAdditionalActionL()
   296     {
   284     {
   297     PRINT( _L( "MM MTP => CRenameObject::PerformAdditionalActionL" ) );
   285     PRINT( _L( "MM MTP => CRenameObject::PerformAdditionalActionL" ) );
   298 
   286 
   299     // update MPX DB
   287     // update MPX DB
   300     TRAPD( err, iWrapper.RenameObjectL( iOldFileName, iFileName ) );
   288     TRAPD( err, iWrapper.RenameObjectL( *iObjectInfo, iFileName ) );
   301 
   289 
   302     // should not fail for 1 file, keep it going, as folder already renamed
   290     // should not fail for 1 file, keep it going, as folder already renamed
   303     if ( err != KErrNone )
   291     if ( err != KErrNone )
   304         PRINT1( _L( "MM MTP <> CRenameObject::PerformAdditionalActionL err = %d" ), err );
   292         PRINT1( _L( "MM MTP <> CRenameObject::PerformAdditionalActionL err = %d" ), err );
   305 
   293