178 } |
179 } |
179 } |
180 } |
180 |
181 |
181 // keep in mind for notification when enumeration complete |
182 // keep in mind for notification when enumeration complete |
182 iStorageId = aStorageId; |
183 iStorageId = aStorageId; |
183 |
184 iEnumState = EEnumPlaylist; |
184 if ( iStorages.Count() > 0 ) |
185 if ( iStorages.Count() > 0 ) |
185 { |
186 { |
186 ScanStorageL( iStorages[0] ); |
187 InitStorageL(); |
187 } |
188 } |
188 else |
189 ScanNextL(); |
189 { |
|
190 iStorages.Reset(); |
|
191 SignalCompleteL( iDataProvider ); |
|
192 } |
|
193 |
190 |
194 PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::StartL" ) ); |
191 PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::StartL" ) ); |
195 } |
192 } |
196 |
193 |
197 // ----------------------------------------------------------------------------- |
194 // ----------------------------------------------------------------------------- |
198 // CAbstractMediaMtpDataProviderEnumerator::ScanStorageL |
195 // CAbstractMediaMtpDataProviderEnumerator::InitStorageL |
199 // Find out all AbstractMedia file according to storage id |
196 // Initialize iAbstractMedia, iCount and iCurrentIndex according to iStorages and iEnumState |
200 // ----------------------------------------------------------------------------- |
197 // ----------------------------------------------------------------------------- |
201 // |
198 // |
202 void CAbstractMediaMtpDataProviderEnumerator::ScanStorageL( TUint32 aStorageId ) |
199 void CAbstractMediaMtpDataProviderEnumerator::InitStorageL() |
203 { |
200 { |
204 PRINT1( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::ScanStorageL aStorageId = 0x%x" ), aStorageId ); |
201 __ASSERT_DEBUG(iStorages.Count() > 0 && iEnumState < EEnumCount, User::Invariant() ); |
|
202 PRINT2( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::InitStorageL storageId = 0x%x, state=%d" ), iStorages[0], iEnumState ); |
205 const CMTPStorageMetaData& storage( |
203 const CMTPStorageMetaData& storage( |
206 iFramework.StorageMgr().StorageL( aStorageId ) ); |
204 iFramework.StorageMgr().StorageL( iStorages[0] ) ); |
207 |
205 |
208 __ASSERT_DEBUG( ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) == |
206 __ASSERT_DEBUG( ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) == |
209 CMTPStorageMetaData::ESystemTypeDefaultFileSystem ), User::Invariant() ); |
207 CMTPStorageMetaData::ESystemTypeDefaultFileSystem ), User::Invariant() ); |
210 |
208 |
211 TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) ); |
209 TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) ); |
212 PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::ScanStorageL StorageSuid = %S" ), &root ); |
210 PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::InitStorageL StorageSuid = %S" ), &root ); |
213 |
211 |
214 // created by windows media player, or else return responsecode is Access denied |
212 if ( iEnumState == EEnumPlaylist ) |
215 // Create playlist directory if it does not exist |
213 { |
216 // NOTE: Only playlist need to create directory here, for the dummy files |
214 // created by windows media player, or else return responsecode is Access denied |
217 HBufC* tempBuf = HBufC::NewLC( KMaxFileName ); // + tempBuf |
215 // Create playlist directory if it does not exist |
218 TPtr folder = tempBuf->Des(); |
216 // NOTE: Only playlist need to create directory here, for the dummy files |
219 folder.Zero(); |
217 HBufC* tempBuf = HBufC::NewLC( KMaxFileName ); // + tempBuf |
220 folder.Append( root ); |
218 TPtr folder = tempBuf->Des(); |
221 folder.Append( KPlaylistFilePath ); |
219 folder.Zero(); |
222 TBool ret = BaflUtils::FileExists( iFramework.Fs(), folder ); |
220 folder.Append( root ); |
223 PRINT2( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::ScanStorageL ret = %d, folder = %S" ), ret, &folder ); |
221 folder.Append( KPlaylistFilePath ); |
224 if( !ret ) |
222 TBool ret = BaflUtils::FileExists( iFramework.Fs(), folder ); |
225 { |
223 PRINT2( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::InitStorageL ret = %d, folder = %S" ), ret, &folder ); |
226 TInt err = iFramework.Fs().MkDirAll( folder ); |
224 if( !ret ) |
227 PRINT2( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::ScanStorageL Creating folder (%S) returned error %d" ), tempBuf, err ); |
225 { |
228 |
226 TInt err = iFramework.Fs().MkDirAll( folder ); |
229 // add this new folder to framework metadata DB |
227 PRINT2( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::InitStorageL Creating folder (%S) returned error %d" ), tempBuf, err ); |
230 CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC( 0, // Dev Dp hard code |
228 |
231 EMTPFormatCodeAssociation, |
229 // add this new folder to framework metadata DB |
232 aStorageId, |
230 CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC( 0, // Dev Dp hard code |
233 folder ); // + object |
231 EMTPFormatCodeAssociation, |
234 object->SetUint( CMTPObjectMetaData::EParentHandle, KMTPHandleNoParent ); |
232 iStorages[0], |
235 object->SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPAssociationTypeGenericFolder ); |
233 folder ); // + object |
236 PERFLOGSTART( KObjectManagerInsert ); |
234 object->SetUint( CMTPObjectMetaData::EParentHandle, KMTPHandleNoParent ); |
237 iObjectMgr.InsertObjectL( *object ); |
235 object->SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPAssociationTypeGenericFolder ); |
238 PERFLOGSTOP( KObjectManagerInsert ); |
236 PERFLOGSTART( KObjectManagerInsert ); |
239 CleanupStack::PopAndDestroy( object ); // - object |
237 iObjectMgr.InsertObjectL( *object ); |
240 } |
238 PERFLOGSTOP( KObjectManagerInsert ); |
241 CleanupStack::PopAndDestroy( tempBuf ); // - tempBuf |
239 CleanupStack::PopAndDestroy( object ); // - object |
|
240 } |
|
241 CleanupStack::PopAndDestroy( tempBuf ); // - tempBuf |
|
242 } |
242 |
243 |
243 // find all abstract medias stored in MPX |
244 // find all abstract medias stored in MPX |
244 delete iAbstractMedias; |
245 delete iAbstractMedias; |
245 iAbstractMedias = NULL; |
246 iAbstractMedias = NULL; |
|
247 TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum; |
246 PERFLOGSTART( KMpxGetAllAbstractMedia ); |
248 PERFLOGSTART( KMpxGetAllAbstractMedia ); |
247 TRAPD( err, iDataProvider.GetWrapperL().GetAllAbstractMediaL( root, &iAbstractMedias, EMPXPlaylist ) ); |
249 TRAPD( err, iDataProvider.GetWrapperL().GetAllAbstractMediaL( root, &iAbstractMedias, category ) ); |
248 PERFLOGSTOP( KMpxGetAllAbstractMedia ); |
250 PERFLOGSTOP( KMpxGetAllAbstractMedia ); |
249 |
251 |
250 if ( iAbstractMedias != NULL && err == KErrNone ) |
252 if ( iAbstractMedias != NULL && err == KErrNone ) |
251 { |
253 { |
252 iCount = iAbstractMedias->Count(); |
254 iCount = iAbstractMedias->Count(); |
253 iCurrentIndex = 0; |
|
254 |
|
255 TRequestStatus* status = &iStatus; |
|
256 User::RequestComplete( status, iStatus.Int() ); |
|
257 SetActive(); |
|
258 } |
255 } |
259 else |
256 else |
260 { |
257 { |
261 iCount = 0; |
258 iCount = 0; |
262 iCurrentIndex = 0; |
259 } |
263 ScanNextL(); |
260 iCurrentIndex = 0; |
264 } |
261 |
265 |
262 PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::InitStorageL" ) ); |
266 PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::ScanStorageL" ) ); |
263 } |
267 } |
264 |
268 |
265 // ----------------------------------------------------------------------------- |
269 // ----------------------------------------------------------------------------- |
266 // CAbstractMediaMtpDataProviderEnumerator::ScanNextL |
270 // CAbstractMediaMtpDataProviderEnumerator::ScanNextStorageL |
267 // Proceed to next abstract media item |
271 // |
|
272 // ----------------------------------------------------------------------------- |
268 // ----------------------------------------------------------------------------- |
273 // |
269 // |
274 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL() |
270 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL() |
275 { |
271 { |
276 PRINT1( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::ScanNextL iStorages.Count = %d" ), iStorages.Count() ); |
272 while (iStorages.Count() > 0) |
277 if ( iCurrentIndex < iCount ) |
273 { |
278 { |
274 while ( iEnumState < EEnumCount ) |
279 TRequestStatus* status = &iStatus; |
275 { |
280 User::RequestComplete( status, iStatus.Int() ); |
276 if ( iCurrentIndex < iCount ) |
281 SetActive(); |
277 { |
282 |
278 TRequestStatus* status = &iStatus; |
283 PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ), |
279 User::RequestComplete( status, iStatus.Int() ); |
284 iCurrentIndex, |
280 SetActive(); |
285 iCount ); |
281 PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ), |
286 } |
282 iCurrentIndex, |
287 // If there are one or more unscanned storages left |
283 iCount ); |
288 // (the currently scanned one is still on the list) |
284 return; |
289 else if ( iStorages.Count() > 1 ) |
285 } |
290 { |
286 ++iEnumState; |
|
287 if (iEnumState == EEnumCount) |
|
288 { |
|
289 break; |
|
290 } |
|
291 InitStorageL(); |
|
292 } |
291 iStorages.Remove( 0 ); |
293 iStorages.Remove( 0 ); |
292 ScanStorageL( iStorages[0] ); |
294 if (iStorages.Count() == 0) |
293 } |
295 { |
294 else |
296 break; |
295 { |
297 } |
296 // We are done |
298 iEnumState = EEnumPlaylist; |
297 PRINT( _L( "MM MTP <> Objects enumeration completed 2" ) ); |
299 InitStorageL(); |
298 iStorages.Reset(); |
300 } |
299 SignalCompleteL( iDataProvider ); |
301 // We are done |
300 } |
302 PRINT( _L( "MM MTP <> Objects enumeration completed" ) ); |
|
303 delete iAbstractMedias; |
|
304 iAbstractMedias = NULL; |
|
305 iStorages.Reset(); |
|
306 SignalCompleteL( iDataProvider ); |
301 } |
307 } |
302 |
308 |
303 // ----------------------------------------------------------------------------- |
309 // ----------------------------------------------------------------------------- |
304 // CAbstractMediaMtpDataProviderEnumerator::RunL |
310 // CAbstractMediaMtpDataProviderEnumerator::RunL |
305 // NOTE: preserve for performance improvement |
311 // NOTE: preserve for performance improvement |
312 // insert all abstract medias into handle db of framework |
318 // insert all abstract medias into handle db of framework |
313 CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex]; |
319 CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex]; |
314 |
320 |
315 // Increase the index first in case of leave |
321 // Increase the index first in case of leave |
316 iCurrentIndex++; |
322 iCurrentIndex++; |
317 |
323 TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum; |
318 HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, EMPXPlaylist ); |
324 HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, category ); |
319 CleanupStack::PushL( abstractMedia ); // + abstractMedia |
325 CleanupStack::PushL( abstractMedia ); // + abstractMedia |
320 AddEntryL( *abstractMedia ); |
326 TBool ret = ETrue; |
321 |
327 if ( iEnumState == EEnumAbstractAlbum ) |
322 // find all reference of each abstract media |
328 { |
323 CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity ); |
329 //The abstract album may be removed, check it first |
324 CleanupStack::PushL( references ); // + references |
330 ret = BaflUtils::FileExists( iFramework.Fs(), *abstractMedia ); |
325 |
331 PRINT2( _L( "MM MTP <> BaflUtils::FileExists( RFs,%S ) ret = %d" ), abstractMedia, ret ); |
326 PERFLOGSTART( KMpxQueryAbstractMediaReference ); |
332 } |
327 iDataProvider.GetWrapperL().GetAllReferenceL( media, *references ); |
333 |
328 PERFLOGSTOP( KMpxQueryAbstractMediaReference ); |
334 if ( ret ) |
329 |
335 { |
330 // insert references into reference db |
336 PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunL abstractMedia=%S" ), abstractMedia ); |
331 AddReferencesL( *abstractMedia, *references ); |
337 AddEntryL( *abstractMedia ); |
332 |
338 |
333 CleanupStack::PopAndDestroy( references ); // - references |
339 // find all reference of each abstract media |
|
340 CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity ); |
|
341 CleanupStack::PushL( references ); // + references |
|
342 |
|
343 PERFLOGSTART( KMpxQueryAbstractMediaReference ); |
|
344 iDataProvider.GetWrapperL().GetAllReferenceL( media, *references ); |
|
345 PERFLOGSTOP( KMpxQueryAbstractMediaReference ); |
|
346 |
|
347 // insert references into reference db |
|
348 AddReferencesL( *abstractMedia, *references ); |
|
349 |
|
350 CleanupStack::PopAndDestroy( references ); // - references |
|
351 } |
334 CleanupStack::PopAndDestroy( abstractMedia ); // - abstractMedia |
352 CleanupStack::PopAndDestroy( abstractMedia ); // - abstractMedia |
335 |
353 |
336 ScanNextL(); |
354 ScanNextL(); |
337 } |
355 } |
338 |
356 |