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