HBufC* CPluginUtils::ConvertUtfToUnicodeL( const TDesC8& aUtf7 )
	{

	RBuf output;
	CleanupClosePushL( output );
	
	TBuf16<20> outputBuffer;
	TPtrC8 remainderOfUtf7( aUtf7 );

	for(;;)
		{
		const TInt returnValue = CnvUtfConverter::ConvertToUnicodeFromUtf8(outputBuffer, remainderOfUtf7);
		if (returnValue==CnvUtfConverter::EErrorIllFormedInput)
			return NULL;
		else if (returnValue<0)
			return NULL;
        
		output.ReAllocL( output.Length() + outputBuffer.Length() );
		output.Append( outputBuffer );

        if (returnValue == 0)
            break;

        remainderOfUtf7.Set(remainderOfUtf7.Right(returnValue));
		}

	HBufC* ret = output.AllocL();
	
	CleanupStack::PopAndDestroy( &output );
	return ret;
	}
/**
A helper function of MoveObjectL.
@param aNewFolderName the new file folder name after the folder is moved.
*/
void CMTPMoveObject::MoveFolderL()
{
    OstTraceFunctionEntry0( CMTPMOVEOBJECT_MOVEFOLDERL_ENTRY );

    RBuf oldFolderName;
    oldFolderName.CreateL(KMaxFileName);
    oldFolderName.CleanupClosePushL();
    oldFolderName = iObjectInfo->DesC(CMTPObjectMetaData::ESuid);
    iPathToMove = oldFolderName.AllocL();

    if (iObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId())
    {
        GetPreviousPropertiesL(oldFolderName);
        // Remove backslash.
        oldFolderName.SetLength(oldFolderName.Length() - 1);
        SetPreviousPropertiesL(*iNewRootFolder);
        _LIT(KBackSlash, "\\");
        oldFolderName.Append(KBackSlash);

        iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, *iNewRootFolder);
        iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle);
        iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
        iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);
    }

    CleanupStack::PopAndDestroy(); // oldFolderName.

    OstTraceFunctionExit0( CMTPMOVEOBJECT_MOVEFOLDERL_EXIT );
}
void CVideoEntry::GenerateThumbnailFileL( const TDesC& aCacheDirectory )
	{
	delete iThumbnailFile;

	RBuf path;
	CleanupClosePushL( path );
	path.Create( aCacheDirectory.Length() + iVideoId->Length() + KCacheFileExtension().Length() );
	path.Copy( aCacheDirectory );
	path.Append( *iVideoId );
	path.Append( KCacheFileExtension() );
	iThumbnailFile = path.AllocL();
	CleanupStack::PopAndDestroy( &path );
	}
/**
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;
}