mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadatampxaccess.cpp
changeset 35 2ee890d2f7e7
parent 32 edd273b3192a
child 50 762d760dcfdf
--- a/mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadatampxaccess.cpp	Thu May 27 13:19:19 2010 +0300
+++ b/mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadatampxaccess.cpp	Fri Jun 11 14:04:53 2010 +0300
@@ -67,10 +67,6 @@
 _LIT( KSetMetadataValue, "SetMetadataValueL" );
 #endif
 
-#ifdef  _DEBUG
-_LIT( KMtpMpxPanic, "CMmMtpDpMetadataMpxAccess" );
-#endif
-
 CMmMtpDpMetadataMpxAccess* CMmMtpDpMetadataMpxAccess::NewL( RFs& aRfs )
     {
     CMmMtpDpMetadataMpxAccess* self = new( ELeave ) CMmMtpDpMetadataMpxAccess( aRfs );
@@ -81,9 +77,10 @@
     return self;
     }
 
-CMmMtpDpMetadataMpxAccess::CMmMtpDpMetadataMpxAccess( RFs& aRfs ):
+CMmMtpDpMetadataMpxAccess::CMmMtpDpMetadataMpxAccess( RFs& aRfs ) :
     iRfs( aRfs ),
-    iSampleData( NULL )
+    iSampleData( NULL ),
+    iHasCleanUp( EFalse )
     {
     // Do nothing
     }
@@ -149,6 +146,7 @@
         iCollectionHelper = NULL;
         }
 
+    iHasCleanUp = EFalse;  // must reset, as class is not always destoryed
     PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::CloseSession" ) );
     }
 
@@ -597,9 +595,14 @@
     // as there is NOT a separate database for deleted files.
     PRINT( _L( "MM MTP <> Deleting metadata for deleted files" ) );
 
-    PERFLOGSTART( KMpxCollectionCleanupDeletedMediasL );
-    CollectionHelperL()->CleanupDeletedMediasL();
-    PERFLOGSTOP( KMpxCollectionCleanupDeletedMediasL );
+    if ( !iHasCleanUp )
+        {
+        PERFLOGSTART( KMpxCollectionCleanupDeletedMediasL );
+        CollectionHelperL()->CleanupDeletedMediasL();
+        PERFLOGSTOP( KMpxCollectionCleanupDeletedMediasL );
+
+        iHasCleanUp = ETrue;
+        }
 
     PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::UpdateMusicCollectionL" ) );
     }
@@ -1000,7 +1003,6 @@
             EMPXSong );
         // File Path
         //
-        TParsePtrC parse( aFullFileName );
         media->SetTextValueL( KMPXMediaGeneralUri, aFullFileName );
         media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() );
 
@@ -1336,7 +1338,7 @@
 // ---------------------------------------------------------------------------
 //
 void CMmMtpDpMetadataMpxAccess::GetAllAbstractMediaL( const TDesC& aStoreRoot,
-    CMPXMediaArray** aAbstractMedias,
+    CDesCArray& aAbstractMedias,
     TMPXGeneralCategory aCategory )
     {
     PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllAbstractMediaL" ) );
@@ -1387,8 +1389,9 @@
             User::Leave( KErrNotSupported );
             }
 
-        *aAbstractMedias =
-            CMPXMediaArray::NewL( *( foundMedia->Value<CMPXMediaArray> ( KMPXMediaArrayContents ) ) );
+        CMPXMediaArray* mediaArray = foundMedia->Value<CMPXMediaArray> ( KMPXMediaArrayContents );
+        for ( TInt i = 0; i < count; i++ )
+            aAbstractMedias.AppendL( ( *mediaArray )[i]->ValueText( KMPXMediaGeneralUri ) );
         }
 
     CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia
@@ -1401,15 +1404,36 @@
 // Get all references of specified playlist
 // ---------------------------------------------------------------------------
 //
-void CMmMtpDpMetadataMpxAccess::GetAllReferenceL( CMPXMedia* aAbstractMedia,
+void CMmMtpDpMetadataMpxAccess::GetAllReferenceL( const TDesC& aRefOwnerSuid,
+    TMPXGeneralCategory aCategory,
     CDesCArray& aReferences )
     {
     PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllReferenceL" ) );
 
-    __ASSERT_DEBUG( aAbstractMedia, User::Panic( KMtpMpxPanic, KErrArgument ) );
+    // 1. Get CMPXMedia object by the reference owner suid
+    RArray<TMPXAttribute> attributes;
+    CleanupClosePushL( attributes ); // + attributes
+    attributes.AppendL( KMPXMediaGeneralId );
+    attributes.AppendL( KMPXMediaGeneralTitle );
+    attributes.AppendL( KMPXMediaGeneralUri );
+
+    CMPXMedia* refOwner = CollectionHelperL()->GetL( aRefOwnerSuid,
+        attributes.Array(),
+        aCategory );
 
-    // Extract the playlist id from the found object
-    TUint32 abstractMediaId = *( *aAbstractMedia ).Value<TMPXItemId>( KMPXMediaGeneralId );
+    __ASSERT_DEBUG( refOwner, Panic( EMmMTPDpObjectNull ) );
+
+    CleanupStack::PushL( refOwner ); // + refOwner
+
+    // 2. Extract the general id from the found object
+    if ( !refOwner->IsSupported( KMPXMediaGeneralId ) )
+        PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllReferenceL Before GeneralId" ) );
+
+    TUint32 abstractMediaId = *( *refOwner ).Value<TMPXItemId>( KMPXMediaGeneralId );
+    PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllReferenceL After GeneralId" ) );
+
+    CleanupStack::PopAndDestroy( refOwner );    // - refOwner
+    CleanupStack::PopAndDestroy( &attributes ); // - attributes
 
     // find the media object that contains a list of songs in the playlist
     RArray<TInt> contentIDs;
@@ -1467,7 +1491,7 @@
 
             // may replace the following 3 statements into the following:
             // AppendL(refMedia->ValueText(KMPXMediaGeneralUri));
-            HBufC* musicFileLocation = refMedia->ValueText( KMPXMediaGeneralUri ).AllocLC();
+            HBufC* musicFileLocation = refMedia->ValueText( KMPXMediaGeneralUri ).AllocLC();    // + musicFileLocation
             aReferences.AppendL( *musicFileLocation );
 
             PRINT1( _L("MM MTP <> CMmMtpDpMetadataMpxAccess::GetAllReferenceL, [%S] found from MPX db"), musicFileLocation );
@@ -1482,33 +1506,6 @@
     }
 
 // ---------------------------------------------------------------------------
-// CMmMtpDpMetadataMpxAccess::GetAbstractMediaNameL
-//
-// ---------------------------------------------------------------------------
-//
-HBufC* CMmMtpDpMetadataMpxAccess::GetAbstractMediaNameL( CMPXMedia* aAbstractMedia,
-    TMPXGeneralCategory aCategory )
-    {
-    PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAbstractMediaNameL" ) );
-    HBufC* name = NULL;
-    if ( aCategory == EMPXPlaylist || aCategory == EMPXAbstractAlbum )
-        {
-        if( !aAbstractMedia->IsSupported( KMPXMediaGeneralUri ) )
-            {
-            User::Leave( KErrNotSupported );
-            }
-        name = aAbstractMedia->ValueText( KMPXMediaGeneralUri ).AllocL();
-        }
-    else
-        {
-        User::Leave( KErrNotSupported );
-        }
-
-    PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetAbstractMediaNameL" ) );
-    return name;
-    }
-
-// ---------------------------------------------------------------------------
 // CMmMtpDpMetadataMpxAccess::GetModifiedContentL
 // Get modified content
 // ---------------------------------------------------------------------------