mtpfws/mtpfw/dataproviders/dputility/src/rmtputility.cpp
changeset 17 aabe5387f5ce
parent 0 d0791faffa3f
child 19 ef55b168cedb
equal deleted inserted replaced
0:d0791faffa3f 17:aabe5387f5ce
   432         }
   432         }
   433     CleanupStack::PopAndDestroy(extensionMapping);
   433     CleanupStack::PopAndDestroy(extensionMapping);
   434     return 1;
   434     return 1;
   435     }
   435     }
   436 
   436 
   437 
       
   438 void RMTPUtility::RenameAllChildrenL(TUint32 aStorageId, TUint32 aParentHandle, const TDesC& aNewFolderName, const TDesC& aOldFolderName)
   437 void RMTPUtility::RenameAllChildrenL(TUint32 aStorageId, TUint32 aParentHandle, const TDesC& aNewFolderName, const TDesC& aOldFolderName)
   439 	{
   438 	{
   440     __FLOG(_L8("RenameAllChildrenL - Entry"));
   439     __FLOG(_L8("RenameAllChildrenL - Entry"));
   441 	
   440     
   442 	RMTPObjectMgrQueryContext   context;
   441     CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC());
   443 	RArray<TUint>               handles;
   442     TInt count = 0; 
   444 	TMTPObjectMgrQueryParams    params(aStorageId, KMTPFormatsAll, aParentHandle);
   443     RArray<TUint>               handles;
   445 	CleanupClosePushL(context);
   444     CleanupClosePushL(handles);
   446 	CleanupClosePushL(handles);
   445     GetAllDecendents(aStorageId, aParentHandle, handles);
   447 	
   446     count = handles.Count();
   448 	CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC());
   447     
   449 	TInt count = 0;	
   448     TEntry entry;
   450 	TEntry entry;
   449     for(TInt i(0); (i < count); ++i)
   451 	
   450         {
   452 	do
   451         if (!iFramework->ObjectMgr().ObjectL(handles[i], *objectInfo))
   453 	    {
   452             {
   454 	    iFramework->ObjectMgr().GetObjectHandlesL(params, context, handles);
   453             User::Leave(KErrCorrupt);
   455     	count = handles.Count();
   454             }
   456     	
   455         
   457     	for(TInt i(0); (i < count); i++)
   456         /**
   458     		{
   457          * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, 
   459     		if (!iFramework->ObjectMgr().ObjectL(handles[i], *objectInfo))
   458          * but it does not really own the format 0x3002.
   460     			{
   459          * 
   461     			User::Leave(KErrCorrupt);
   460          * Make the same behavior betwen 0x3000 and 0x3002.
   462     			}
   461          */
   463     		
   462         if( (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation)
   464     	    /**
   463             && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeUndefined)
   465     	     * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, 
   464             && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeScript) )
   466     	     * but it does not really own the format 0x3002.
   465            continue;
   467     	     * 
   466 
   468     	     * Make the same behavior betwen 0x3000 and 0x3002.
   467         RBuf entryName; 
   469     	     */
   468         entryName.CreateL(KMaxFileName);
   470     		if( (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation)
   469         entryName.CleanupClosePushL();
   471     		    && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeUndefined)
   470         entryName = objectInfo->DesC(CMTPObjectMetaData::ESuid);
   472     		    && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeScript) )
   471         
   473     		   continue;
   472         RBuf rightPartName;
   474 
   473         rightPartName.CreateL(KMaxFileName);
   475 			RBuf entryName; 
   474         rightPartName.CleanupClosePushL();
   476 			entryName.CreateL(KMaxFileName);
   475         rightPartName = entryName.Right(entryName.Length() - aOldFolderName.Length());
   477 			entryName.CleanupClosePushL();
   476         
   478 			entryName = objectInfo->DesC(CMTPObjectMetaData::ESuid);
   477         if ((aNewFolderName.Length() + rightPartName.Length()) > entryName.MaxLength())
   479 			
   478             {
   480 			RBuf rightPartName;
   479             entryName.ReAllocL(aNewFolderName.Length() + rightPartName.Length());
   481 			rightPartName.CreateL(KMaxFileName);
   480             }
   482 			rightPartName.CleanupClosePushL();
   481         
   483 			rightPartName = entryName.Right(entryName.Length() - aOldFolderName.Length());
   482         entryName.Zero();
   484 			
   483         entryName.Append(aNewFolderName);
   485 			if ((aNewFolderName.Length() + rightPartName.Length()) > entryName.MaxLength())
   484         entryName.Append(rightPartName);
   486 				{
   485         
   487 				entryName.ReAllocL(aNewFolderName.Length() + rightPartName.Length());
   486         if (KErrNone != iFramework->Fs().Entry(entryName, entry))
   488 				}
   487             {
   489 			
   488             // Skip objects that don't use the file path as SUID.
   490 			entryName.Zero();
   489             CleanupStack::PopAndDestroy(&entryName);
   491 			entryName.Append(aNewFolderName);
   490             continue;
   492 			entryName.Append(rightPartName);
   491             }        
   493 			
   492         
   494 			if (KErrNone != iFramework->Fs().Entry(entryName, entry))
   493         TFileName oldfilename(objectInfo->DesC(CMTPObjectMetaData::ESuid));
   495 				{
   494         objectInfo->SetDesCL(CMTPObjectMetaData::ESuid, entryName);
   496 				// Skip objects that don't use the file path as SUID.
   495         iFramework->ObjectMgr().ModifyObjectL(*objectInfo);
   497 				CleanupStack::PopAndDestroy(&entryName);
   496         
   498 				continue;
   497         if(objectInfo->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation)
   499 				}
   498             {
   500 			
   499             //Send the Rename notification 
   501 			// Recursively update all this object's children.
   500             TMTPNotificationParamsHandle param = { handles[i], oldfilename};
   502 			// The maximum recursion depth is as deep as the association hierarchy.
   501             iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(&param));
   503 			RenameAllChildrenL(objectInfo->Uint(CMTPObjectMetaData::EStorageId), objectInfo->Uint(CMTPObjectMetaData::EHandle), entryName, objectInfo->DesC(CMTPObjectMetaData::ESuid) );
   502             }
   504 			
   503             
   505 			TFileName oldfilename(objectInfo->DesC(CMTPObjectMetaData::ESuid));
   504         CleanupStack::PopAndDestroy(2); // rightPartName, entryName             
   506 			objectInfo->SetDesCL(CMTPObjectMetaData::ESuid, entryName);
   505         }
   507 			iFramework->ObjectMgr().ModifyObjectL(*objectInfo);
   506     
   508 			
   507     CleanupStack::PopAndDestroy(2); //objectInfo; &handles; 
   509 			if(objectInfo->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation)
       
   510 				{
       
   511 				//Send the Rename notification 
       
   512 				TMTPNotificationParamsHandle param = { handles[i], oldfilename};
       
   513 				iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(&param));
       
   514 				}
       
   515 			CleanupStack::PopAndDestroy(2); // rightPartName, entryName		
       
   516     		}
       
   517 	    }
       
   518 	while (!context.QueryComplete());
       
   519 	
       
   520 	CleanupStack::PopAndDestroy(3);//objectInfo; &handles; &context
       
   521 	
   508 	
   522     __FLOG(_L8("RenameAllChildrenL - Exit"));
   509     __FLOG(_L8("RenameAllChildrenL - Exit"));
   523 	}
   510 	}
       
   511 
       
   512 void RMTPUtility::GetAllDecendents(TUint32 aStorageId, TUint aParentHandle, RArray<TUint>& aHandles) const
       
   513     {
       
   514     TInt index = 0; 
       
   515     TBool firstLevel = ETrue;
       
   516     
       
   517     do
       
   518         {
       
   519         TUint parentHandle;
       
   520         if (firstLevel)
       
   521             {
       
   522             parentHandle = aParentHandle; //Get the first level children handles
       
   523             firstLevel = EFalse;
       
   524             }        
       
   525         else
       
   526             {
       
   527             parentHandle = aHandles[index];
       
   528             ++index;
       
   529             }        
       
   530         
       
   531         RMTPObjectMgrQueryContext   context;
       
   532         RArray<TUint>               childrenHandles;
       
   533         TMTPObjectMgrQueryParams    params(aStorageId, KMTPFormatsAll, parentHandle);
       
   534         CleanupClosePushL(context);
       
   535         CleanupClosePushL(childrenHandles);
       
   536         
       
   537         do
       
   538             {
       
   539             iFramework->ObjectMgr().GetObjectHandlesL(params, context, childrenHandles);
       
   540             TInt count = childrenHandles.Count(); 
       
   541             for (TUint i = 0; i < count; ++i)
       
   542                 {
       
   543                 aHandles.Append(childrenHandles[i]);
       
   544                 }
       
   545             }
       
   546         while (!context.QueryComplete());
       
   547         CleanupStack::PopAndDestroy(2); //&childrenHandles; &context
       
   548         }
       
   549     while(index < aHandles.Count());
       
   550 
       
   551     }
   524 
   552 
   525 HBufC* RMTPUtility::OdfMimeTypeL( const TDesC& aFullPath )
   553 HBufC* RMTPUtility::OdfMimeTypeL( const TDesC& aFullPath )
   526     {
   554     {
   527     HBufC* mimebuf = NULL;
   555     HBufC* mimebuf = NULL;
   528     
   556