/**
Copy object operation
@return the object handle of the resulting object.
*/
TMTPResponseCode CMTPImageDpCopyObject::CopyObjectL(TUint32& aNewHandle)
    {
    OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_COPYOBJECTL_ENTRY );
    TMTPResponseCode responseCode = EMTPRespCodeOK;
    aNewHandle = KMTPHandleNone;
    
    GetParametersL();
    
    iNewFileName.Append(*iDest);
    const TDesC& oldFileName = iSrcObjectInfo->DesC(CMTPObjectMetaData::ESuid);
    TParsePtrC fileNameParser(oldFileName);
    
    if((iNewFileName.Length() + fileNameParser.NameAndExt().Length()) <= iNewFileName.MaxLength())
        {
        iNewFileName.Append(fileNameParser.NameAndExt());
        responseCode = CanCopyObjectL(oldFileName, iNewFileName);	
        }
    else
        {
        responseCode = EMTPRespCodeGeneralError;
        }
        
    
    if(responseCode == EMTPRespCodeOK)
        {
        aNewHandle = CopyFileL(oldFileName, iNewFileName);
        }
    OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_COPYOBJECTL_EXIT );
    return responseCode;
    }
Example #2
0
// -----------------------------------------------------------------------------
// CMoveObject::MoveObjectL
// Move object operation
// -----------------------------------------------------------------------------
//
void CMoveObject::MoveObjectL()
    {
    PRINT( _L( "MM MTP => CMoveObject::MoveObjectL" ) );
    TMTPResponseCode responseCode = EMTPRespCodeOK;

    GetParametersL();

    RBuf newObjectName;
    newObjectName.CreateL( KMaxFileName );
    newObjectName.CleanupClosePushL(); // + newObjectName
    newObjectName = *iDest;

    TPtrC suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
    TParsePtrC fileNameParser( suid );
    if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() )
        <= newObjectName.MaxLength() )
        {
        newObjectName.Append( fileNameParser.NameAndExt() );
        responseCode = CanMoveObjectL( suid, newObjectName );

        if ( responseCode == EMTPRespCodeOK )
            MoveFileL( newObjectName );
        }
    else
        // Destination is not appropriate for the full path name shouldn't be longer than 255
        responseCode = EMTPRespCodeInvalidDataset;

    SendResponseL( responseCode );

    CleanupStack::PopAndDestroy( &newObjectName ); // - newObjectName

    PRINT1( _L( "MM MTP <= CMoveObject::MoveObjectL responseCode = 0x%x" ), responseCode );
    }
/**
move object operations
@return A valid MTP response code.
*/
TMTPResponseCode CMTPMoveObject::MoveObjectL()
{
    OstTraceFunctionEntry0( CMTPMOVEOBJECT_MOVEOBJECTL_ENTRY );
    TMTPResponseCode responseCode = EMTPRespCodeOK;

    GetParametersL();

    RBuf newObjectName;
    newObjectName.CreateL(KMaxFileName);
    newObjectName.CleanupClosePushL();
    newObjectName = *iDest;

    const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
    TParsePtrC fileNameParser(suid);

    // Check if the object is a folder or a file.
    if(!iIsFolder)
    {
        if((newObjectName.Length() + fileNameParser.NameAndExt().Length()) <= newObjectName.MaxLength())
        {
            newObjectName.Append(fileNameParser.NameAndExt());
        }
        responseCode = CanMoveObjectL(suid, newObjectName);
    }
    else // It is a folder.
    {
        TFileName rightMostFolderName;
        LEAVEIFERROR(BaflUtils::MostSignificantPartOfFullName(suid, rightMostFolderName),
                     OstTraceExt1( TRACE_ERROR, DUP1_CMTPMOVEOBJECT_MOVEOBJECTL, "extract most significant part of %S failed", suid));

        if((newObjectName.Length() + rightMostFolderName.Length() + 1) <= newObjectName.MaxLength())
        {
            newObjectName.Append(rightMostFolderName);
            // Add backslash.
            _LIT(KBackSlash, "\\");
            newObjectName.Append(KBackSlash);
        }
    }

    iNewRootFolder = newObjectName.AllocL();
    OstTraceExt1( TRACE_NORMAL, CMTPMOVEOBJECT_MOVEOBJECTL, "%S", *iNewRootFolder );

    if(responseCode == EMTPRespCodeOK)
    {
        delete iFileMan;
        iFileMan = NULL;
        iFileMan = CFileMan::NewL(iFramework.Fs());

        if(!iIsFolder)
        {
            MoveFileL(newObjectName);
        }
        else
        {
            MoveFolderL();
            SendResponseL(responseCode);
        }
    }
    CleanupStack::PopAndDestroy(); // newObjectName.
    OstTraceFunctionExit0( CMTPMOVEOBJECT_MOVEOBJECTL_EXIT );
    return responseCode;
}