|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Meta data Mpx access |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // from Symbian MTP |
|
20 #include <mtp/tmtptypeuint8.h> |
|
21 #include <mtp/tmtptypeuint16.h> |
|
22 #include <mtp/tmtptypeuint32.h> |
|
23 #include <mtp/tmtptypeuint64.h> |
|
24 #include <mtp/tmtptypeuint128.h> |
|
25 #include <mtp/cmtptypestring.h> |
|
26 #include <mtp/cmtptypearray.h> |
|
27 #include <mtp/cmtpobjectmetadata.h> |
|
28 #include <mtp/mmtpdataproviderframework.h> |
|
29 #include <mtp/mmtpreferencemgr.h> |
|
30 #include <mtp/mtpprotocolconstants.h> |
|
31 // from MPX |
|
32 #include <mpxmedia.h> |
|
33 #include <mpxmediaarray.h> |
|
34 #include <mpxmediamusicdefs.h> |
|
35 #include <mpxmediageneraldefs.h> |
|
36 #include <mpxmediaaudiodefs.h> |
|
37 #include <mpxmediamtpdefs.h> |
|
38 #include <mpxmediacontainerdefs.h> |
|
39 #include <mpxcollectionhelperfactory.h> |
|
40 #include <mpxcollectionhelper.h> |
|
41 #include <pathinfo.h> |
|
42 |
|
43 #include "cmmmtpdpmetadatampxaccess.h" |
|
44 #include "mmmtpdplogger.h" |
|
45 #include "mmmtpdputility.h" |
|
46 #include "tmmmtpdppanic.h" |
|
47 |
|
48 static const TInt KMtpInvalidSongID = 0x1FFFFFFF; |
|
49 static const TInt KMtpChannelMono = 1; |
|
50 static const TInt KMtpChannelStereo = 2; |
|
51 static const TInt KMtpDateTimeStringLength = 15; |
|
52 static const TInt KMtpMaxStringLength = 255; |
|
53 static const TInt KMtpMaxDescriptionLength = 0x200; |
|
54 |
|
55 _LIT( KMtpDateTimeFormat, "%F%Y%M%DT%H%T%S" ); |
|
56 _LIT( KMtpDateTimeConnector, "T" ); |
|
57 _LIT( KEmptyText, "" ); |
|
58 |
|
59 #ifdef _DEBUG |
|
60 _LIT( KMtpMpxPanic, "CMmMtpDpMetadataMpxAccess" ); |
|
61 #endif |
|
62 |
|
63 CMmMtpDpMetadataMpxAccess* CMmMtpDpMetadataMpxAccess::NewL( RFs& aRfs, |
|
64 MMTPDataProviderFramework& aFramework ) |
|
65 { |
|
66 CMmMtpDpMetadataMpxAccess* self = new(ELeave) CMmMtpDpMetadataMpxAccess( aRfs, aFramework ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop( self ); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 CMmMtpDpMetadataMpxAccess::CMmMtpDpMetadataMpxAccess( RFs& aRfs, |
|
75 MMTPDataProviderFramework& aFramework ): |
|
76 iRfs( aRfs ), |
|
77 iFramework( aFramework ) |
|
78 { |
|
79 |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CMmMtpDpMetadataMpxAccess::ConstructL |
|
84 // Second-phase |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CMmMtpDpMetadataMpxAccess::ConstructL() |
|
88 { |
|
89 // for performance measurement purpose |
|
90 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG) |
|
91 iPerfLog = CMmMtpDpPerfLog::NewL( _L( "CMmMtpDpMetadataMpxAccess" ) ); |
|
92 #endif |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CMmMtpDpMetadataMpxAccess::~CMmMtpDpMetadataMpxAccess |
|
97 // Destructor |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CMmMtpDpMetadataMpxAccess::~CMmMtpDpMetadataMpxAccess() |
|
101 { |
|
102 if ( iCollectionHelper ) |
|
103 { |
|
104 iCollectionHelper->Close(); |
|
105 iCollectionHelper = NULL; |
|
106 } |
|
107 |
|
108 // for performance measurement purpose |
|
109 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG) |
|
110 delete iPerfLog; |
|
111 #endif |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL |
|
116 // Gets a piece of metadata from the collection |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL( const TUint16 aPropCode, |
|
120 MMTPType& aNewData, |
|
121 const CMTPObjectMetaData& aObjectMetaData ) |
|
122 { |
|
123 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL aPropCode = 0x%x" ), aPropCode ); |
|
124 |
|
125 // File Path |
|
126 HBufC* suid = aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ).AllocLC(); // + suid |
|
127 TUint format = aObjectMetaData.Uint( CMTPObjectMetaData::EFormatCode ); |
|
128 TMPXGeneralCategory category = ( format == EMTPFormatCodeAbstractAudioVideoPlaylist ) || |
|
129 ( format == EMTPFormatCodeM3UPlaylist ) ? EMPXPlaylist : EMPXSong; |
|
130 |
|
131 PERFLOGSTART( KMpxCollectionGetL ); |
|
132 const CMPXMedia& media = CollectionHelperL()->GetL( *suid, category ); |
|
133 PERFLOGSTOP( KMpxCollectionGetL ); |
|
134 |
|
135 CleanupStack::PopAndDestroy( suid ); // - suid |
|
136 |
|
137 TMPXAttributeData attrib( MpxAttribFromPropL( media, aPropCode ) ); |
|
138 TBool isSupported = media.IsSupported( attrib ); |
|
139 PRINT1(_L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL isSupported = %d" ), isSupported); |
|
140 |
|
141 if ( aPropCode != EMTPObjectPropCodeOriginalReleaseDate |
|
142 && aPropCode != EMTPObjectPropCodeDRMStatus |
|
143 && !isSupported ) |
|
144 { |
|
145 User::Leave( KErrNotSupported ); |
|
146 } |
|
147 |
|
148 switch ( aPropCode ) |
|
149 { |
|
150 case EMTPObjectPropCodeName: |
|
151 case EMTPObjectPropCodeArtist: |
|
152 case EMTPObjectPropCodeAlbumName: |
|
153 case EMTPObjectPropCodeComposer: |
|
154 case EMTPObjectPropCodeGenre: |
|
155 case EMTPObjectPropCodeAlbumArtist: |
|
156 { |
|
157 if ( EMTPTypeString == aNewData.Type() ) |
|
158 { |
|
159 ( ( CMTPTypeString& ) aNewData ).SetL( media.ValueText( attrib ) ); |
|
160 } |
|
161 else |
|
162 { |
|
163 User::Leave( KErrArgument ); |
|
164 } |
|
165 } |
|
166 break; |
|
167 |
|
168 case EMTPObjectPropCodeDescription: |
|
169 { |
|
170 HBufC* data; |
|
171 data = media.ValueText( KMPXMediaGeneralComment ).AllocLC(); // + data |
|
172 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue data = %S" ), data ); |
|
173 if ( EMTPTypeAUINT16 == aNewData.Type() ) |
|
174 { |
|
175 TInt len = data->Length(); |
|
176 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue len = %d" ),len ); |
|
177 if( len != 0 ) |
|
178 { |
|
179 for( TInt i = 0; i < len; i++ ) |
|
180 ( ( CMTPTypeArray& ) aNewData ).AppendUintL( (*data)[i] ); |
|
181 } |
|
182 } |
|
183 else |
|
184 { |
|
185 User::Leave( KErrArgument ); |
|
186 } |
|
187 CleanupStack::PopAndDestroy( data ); // - data |
|
188 } |
|
189 break; |
|
190 |
|
191 case EMTPObjectPropCodeDateModified: |
|
192 case EMTPObjectPropCodeDateAdded: |
|
193 case EMTPObjectPropCodeDateCreated: |
|
194 { |
|
195 TTime time( *media.Value<TInt64> ( attrib ) ); |
|
196 TBuf<KMtpDateTimeStringLength> timeStr; |
|
197 time.FormatL( timeStr, KMtpDateTimeFormat ); |
|
198 |
|
199 if ( EMTPTypeString == aNewData.Type() ) |
|
200 { |
|
201 ( ( CMTPTypeString & ) aNewData ).SetL( timeStr ); |
|
202 } |
|
203 else |
|
204 { |
|
205 User::Leave( KErrArgument ); |
|
206 } |
|
207 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue - get DC4E DateAdded = %Ld" ), time.Int64() ); |
|
208 } |
|
209 break; |
|
210 |
|
211 case EMTPObjectPropCodeDuration: |
|
212 case EMTPObjectPropCodeAudioBitRate: |
|
213 case EMTPObjectPropCodeSampleRate: |
|
214 case EMTPObjectPropCodeAudioWAVECodec: |
|
215 { |
|
216 if ( EMTPTypeUINT32 == aNewData.Type() ) |
|
217 { |
|
218 ( ( TMTPTypeUint32& ) aNewData ).Set( *media.Value<TUint32>( attrib ) ); |
|
219 } |
|
220 else |
|
221 { |
|
222 User::Leave( KErrArgument ); |
|
223 } |
|
224 } |
|
225 break; |
|
226 |
|
227 case EMTPObjectPropCodeTrack: |
|
228 { |
|
229 TLex lex( media.ValueText( attrib ) ); |
|
230 TUint16 uint16( 0 ); |
|
231 lex.Val( uint16, EDecimal ); |
|
232 |
|
233 if ( EMTPTypeUINT16 == aNewData.Type() ) |
|
234 { |
|
235 ( ( TMTPTypeUint16 & ) aNewData ).Set( uint16 ); |
|
236 } |
|
237 else |
|
238 { |
|
239 User::Leave( KErrArgument ); |
|
240 } |
|
241 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue - get DC8B Track = %d" ), uint16 ); |
|
242 } |
|
243 break; |
|
244 |
|
245 case EMTPObjectPropCodeOriginalReleaseDate: |
|
246 { |
|
247 // Compose DateTime string in format YYYYMMDDTHHMMSS |
|
248 TBuf<KMtpDateTimeStringLength> dateTime; |
|
249 dateTime.Zero(); |
|
250 |
|
251 // NOTE: Handled specially, shouldn't leave like other property, following S60 |
|
252 if ( !isSupported ) |
|
253 { |
|
254 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue 0xDC99 date hasn't been set before" ) ); |
|
255 dateTime.Copy( KEmptyText ); |
|
256 } |
|
257 else |
|
258 { |
|
259 TTime time = *media.Value<TInt64> ( attrib ); |
|
260 #ifdef _DEBUG |
|
261 RDebug::Print( _L( "MM MTP <> GetObjectMetadataValue 0xDC99 time = %Ld, Year = %d, Month = %d, Day = %d, Hour = %d, Minute = %d, Second = %d" ), |
|
262 time.Int64(), |
|
263 time.DateTime().Year(), |
|
264 time.DateTime().Month(), |
|
265 time.DateTime().Day(), |
|
266 time.DateTime().Hour(), |
|
267 time.DateTime().Minute(), |
|
268 time.DateTime().Second() ); |
|
269 #endif // _DEBUG |
|
270 // Compose DateTime string in format YYYYMMDDTHHMMSS |
|
271 dateTime.AppendNumFixedWidth( time.DateTime().Year(), |
|
272 EDecimal, |
|
273 4 ); |
|
274 dateTime.AppendNumFixedWidth( time.DateTime().Month() + 1, |
|
275 EDecimal, |
|
276 2 ); |
|
277 dateTime.AppendNumFixedWidth( time.DateTime().Day() + 1, |
|
278 EDecimal, |
|
279 2 ); |
|
280 dateTime.Append( KMtpDateTimeConnector ); |
|
281 dateTime.AppendNumFixedWidth( time.DateTime().Hour(), |
|
282 EDecimal, |
|
283 2 ); |
|
284 dateTime.AppendNumFixedWidth( time.DateTime().Minute(), |
|
285 EDecimal, 2 ); |
|
286 dateTime.AppendNumFixedWidth( time.DateTime().Second(), |
|
287 EDecimal, 2 ); |
|
288 |
|
289 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue 0xDC99 dateString = %S" ), &dateTime ); |
|
290 } |
|
291 if ( EMTPTypeString == aNewData.Type() ) |
|
292 { |
|
293 ( ( CMTPTypeString & ) aNewData ).SetL( dateTime ); |
|
294 } |
|
295 else |
|
296 { |
|
297 User::Leave( KErrArgument ); |
|
298 } |
|
299 } |
|
300 break; |
|
301 |
|
302 case EMTPObjectPropCodeNumberOfChannels: |
|
303 case EMTPObjectPropCodeDRMStatus: |
|
304 if ( !isSupported) |
|
305 { |
|
306 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue 0xDC9D date hasn't been set before" ) ); |
|
307 TInt16 zeroValue = 0x0; |
|
308 ( ( TMTPTypeUint16 & ) aNewData ).Set( zeroValue ); |
|
309 } |
|
310 else |
|
311 { |
|
312 if (EMTPTypeUINT16 == aNewData.Type() ) |
|
313 { |
|
314 ( ( TMTPTypeUint16 & ) aNewData ).Set( *media.Value<TUint16>(attrib) ); |
|
315 } |
|
316 else |
|
317 { |
|
318 User::Leave(KErrArgument); |
|
319 } |
|
320 } |
|
321 break; |
|
322 |
|
323 default: |
|
324 { |
|
325 User::Leave( KErrNotSupported ); |
|
326 } |
|
327 break; |
|
328 } |
|
329 |
|
330 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL" ) ); |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CMmMtpDpMetadataMpxAccess::CollectionHelperL |
|
335 // Returns the collection helper |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 MMPXCollectionHelper* CMmMtpDpMetadataMpxAccess::CollectionHelperL() |
|
339 { |
|
340 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::CollectionHelperL()" ) ); |
|
341 |
|
342 // This is for the case when drive is completely full but Music DB is not |
|
343 // yet created. NewCollectionCachedHelperL() will attempt to create a |
|
344 // DB file on the spot when MPX Collection helper is accessed. For the |
|
345 // case of Music DB creation failure, it will be handled by MTP server |
|
346 // as a General Error |
|
347 if ( iCollectionHelper == NULL ) |
|
348 { |
|
349 PERFLOGSTART(KMpxCollectionNewL); |
|
350 iCollectionHelper = CMPXCollectionHelperFactory::NewCollectionCachedHelperL(); |
|
351 PERFLOGSTOP(KMpxCollectionNewL); |
|
352 |
|
353 // Do a search for a song ID that does not exist |
|
354 // This is to validate the presence of the media database. |
|
355 RArray<TInt> contentIDs; |
|
356 CleanupClosePushL( contentIDs ); // + contentIDs |
|
357 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
358 |
|
359 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
360 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
361 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
362 |
|
363 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
364 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
365 searchMedia->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, |
|
366 KMtpInvalidSongID ); |
|
367 searchMedia->SetTextValueL( KMPXMediaGeneralDrive, iStoreRoot ); |
|
368 |
|
369 RArray<TMPXAttribute> songAttributes; |
|
370 CleanupClosePushL( songAttributes ); // + songAttributes |
|
371 songAttributes.AppendL( KMPXMediaGeneralId ); |
|
372 |
|
373 CMPXMedia* foundMedia = NULL; |
|
374 |
|
375 PERFLOGSTART( KMpxCollectionFindAllLValidate ); |
|
376 TRAPD( err, foundMedia = iCollectionHelper->FindAllL( |
|
377 *searchMedia, |
|
378 songAttributes.Array() ) ); |
|
379 PERFLOGSTOP( KMpxCollectionFindAllLValidate ); |
|
380 |
|
381 CleanupStack::PopAndDestroy( &songAttributes ); // - songAttributes |
|
382 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
383 |
|
384 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
385 if ( err != KErrNone ) |
|
386 { |
|
387 PRINT1( _L("MM MTP <> CMmMtpDpMetadataMpxAccess::CollectionHelperL() Had err (%d) accessing the Music Database!!!"), err ); |
|
388 // Delete the collection helper for now |
|
389 iCollectionHelper->Close(); |
|
390 iCollectionHelper = NULL; |
|
391 User::Leave( KErrGeneral ); |
|
392 } |
|
393 else |
|
394 { |
|
395 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::CollectionHelperL() Music Database successfully created and validated!!!" ) ); |
|
396 } |
|
397 |
|
398 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
399 } |
|
400 |
|
401 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::CollectionHelperL()" ) ); |
|
402 return iCollectionHelper; |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // CMmMtpDpMetadataMpxAccess::FindWMPMediaLC |
|
407 // Finds Media with specific WMP values |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 CMPXMedia* CMmMtpDpMetadataMpxAccess::FindWMPMediaLC( TMPXAttributeData aWMPMediaID, |
|
411 TBool aFlag ) |
|
412 { |
|
413 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::FindWMPMediaLC" ) ); |
|
414 |
|
415 CMPXMedia* searchMedia = CMPXMedia::NewL(); |
|
416 CleanupStack::PushL( searchMedia ); // + searchMeida |
|
417 |
|
418 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup ); |
|
419 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
420 searchMedia->SetTObjectValueL<TBool>( aWMPMediaID, aFlag ); |
|
421 |
|
422 searchMedia->SetTextValueL( KMPXMediaGeneralDrive, iStoreRoot ); |
|
423 |
|
424 RArray<TMPXAttribute> songAttributes; |
|
425 CleanupClosePushL( songAttributes ); // + songAttributes |
|
426 songAttributes.AppendL( KMPXMediaGeneralUri ); |
|
427 |
|
428 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::FindWMPMediaLC searchMedia setup with no problems" ) ); |
|
429 |
|
430 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( |
|
431 *searchMedia, |
|
432 songAttributes.Array() ); |
|
433 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::FindWMPMediaLC foundMedia assigned from FindAllL" ) ); |
|
434 |
|
435 CleanupStack::PopAndDestroy( &songAttributes ); // - songAttributes |
|
436 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
437 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
438 |
|
439 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
440 { |
|
441 User::Leave( KErrNotSupported ); |
|
442 } |
|
443 |
|
444 #ifdef _DEBUG |
|
445 TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
446 PRINT1( _L( "MM MTP <> %d Media Objects found in the WMP search" ), foundItemCount ); |
|
447 #endif |
|
448 |
|
449 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::FindWMPMediaLC" ) ); |
|
450 return foundMedia; |
|
451 } |
|
452 |
|
453 // --------------------------------------------------------------------------- |
|
454 // Update the Sync flag for those not synchronized, Update the Modified flag for those have been modified, and delete the stale |
|
455 // records for files that have been deleted. |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 void CMmMtpDpMetadataMpxAccess::UpdateMusicCollectionL() |
|
459 { |
|
460 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::UpdateMusicCollectionL" ) ); |
|
461 CMPXMedia* foundMedia= NULL; |
|
462 TInt foundItemCount( 0 ); |
|
463 |
|
464 // We Should Consider this!!! |
|
465 // if (iWmpRoundTripUsed) // Only update values if they've been read by the PC... |
|
466 // { |
|
467 // Change flag on acquired content so they won't be reported twice |
|
468 |
|
469 //when thousands of the file are being copied in with mass storage, and MTP is connected/disconnected for the first time |
|
470 //updateing the sync bit cause a serious performance issue issue |
|
471 //since our DP is not presistent, and we are not depedns on KMPXMediaGeneralSynchronized flag to tell whether a file is newly added or not |
|
472 //reseting this flag is not needed in reality, comment out for now |
|
473 /*foundMedia = FindWMPMediaLC( KMPXMediaGeneralSynchronized, EFalse );// + foundMedia |
|
474 |
|
475 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
476 { |
|
477 User::Leave( KErrNotSupported ); |
|
478 } |
|
479 |
|
480 foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
481 |
|
482 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::UpdateMusicCollectionL found %d Media Objects" ), foundItemCount ); |
|
483 |
|
484 if ( foundItemCount ) |
|
485 { |
|
486 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
487 { |
|
488 User::Leave( KErrNotSupported ); |
|
489 } |
|
490 |
|
491 const CMPXMediaArray* foundArray = foundMedia->Value<CMPXMediaArray>( |
|
492 KMPXMediaArrayContents ); |
|
493 |
|
494 for ( TInt j = 0; j < foundItemCount; j++ ) |
|
495 { |
|
496 CMPXMedia* media = CMPXMedia::NewL( *(*foundArray)[j] ); |
|
497 CleanupStack::PushL( media ); |
|
498 media->SetTObjectValueL<TBool>( |
|
499 KMPXMediaGeneralSynchronized, |
|
500 ETrue ); |
|
501 // Update the song's metadata with the media object |
|
502 PERFLOGSTART(KMpxCollectionSetL); |
|
503 CollectionHelperL()->SetL( media ); |
|
504 PERFLOGSTOP(KMpxCollectionSetL); |
|
505 |
|
506 CleanupStack::PopAndDestroy( media ); |
|
507 } |
|
508 } |
|
509 |
|
510 CleanupStack::PopAndDestroy( foundMedia );// - foundMedia*/ |
|
511 |
|
512 //we are indeed depends on KMPXMediaGeneralModified for modified content to be report correctly |
|
513 //hence it should be reset everytime to ensure integrity |
|
514 // Change flag for files with updated metadata |
|
515 PRINT( _L( "MM MTP <> Updating the mod bit for files..." ) ); |
|
516 |
|
517 foundMedia = FindWMPMediaLC( KMPXMediaGeneralModified, ETrue ); // + foundMedia |
|
518 |
|
519 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
520 { |
|
521 User::Leave( KErrNotSupported ); |
|
522 } |
|
523 |
|
524 foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
525 |
|
526 PRINT1( _L( "MM MTP <> CMtpMpxMetadataAccess::UpdateMusicCollectionL found %d Media Objects" ), foundItemCount ); |
|
527 |
|
528 if ( foundItemCount ) |
|
529 { |
|
530 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
531 { |
|
532 User::Leave( KErrNotSupported ); |
|
533 } |
|
534 |
|
535 const CMPXMediaArray* foundArray2 = foundMedia->Value<CMPXMediaArray>( |
|
536 KMPXMediaArrayContents ); |
|
537 |
|
538 for ( TInt j = 0; j < foundItemCount; j++ ) |
|
539 { |
|
540 CMPXMedia* media = CMPXMedia::NewL( *(*foundArray2)[j] ); |
|
541 CleanupStack::PushL( media ); // + media |
|
542 media->SetTObjectValueL<TBool>( |
|
543 KMPXMediaGeneralModified, |
|
544 EFalse ); |
|
545 // Update the song's metadata with the media object |
|
546 PERFLOGSTART(KMpxCollectionSetL); |
|
547 CollectionHelperL()->SetL( media ); |
|
548 PERFLOGSTOP(KMpxCollectionSetL); |
|
549 |
|
550 CleanupStack::PopAndDestroy( media ); // - media |
|
551 } |
|
552 } |
|
553 |
|
554 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
555 |
|
556 //although as a non-presistent DP, we are not depending on KMPXMediaGeneralDeleted to report deleted file, |
|
557 //however, mark as deleted entry should be cleanup to improve music db performance |
|
558 // Delete stale records from the audio collection, for files that have been deleted. |
|
559 // Records are deleted everytime in CloseSession to improve the audio database performance |
|
560 // as there is NOT a separate database for deleted files. |
|
561 PRINT( _L( "MM MTP <> Deleting metadata for deleted files" ) ); |
|
562 |
|
563 CollectionHelperL()->CleanupDeletedMediasL(); |
|
564 |
|
565 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::UpdateMusicCollectionL" ) ); |
|
566 } |
|
567 |
|
568 // ----------------------------------------------------------------------------- |
|
569 // CMmMtpDpMetadataMpxAccess::RemoveL |
|
570 // Remove the file from MPX DB |
|
571 // ----------------------------------------------------------------------------- |
|
572 // |
|
573 void CMmMtpDpMetadataMpxAccess::DeleteObjectL( const TDesC& aFullFileName, |
|
574 TMPXGeneralCategory aCategory ) |
|
575 { |
|
576 TRAPD( err, CollectionHelperL()->RemoveL( aFullFileName, aCategory ) ); |
|
577 |
|
578 if ( err == KErrNotFound ) |
|
579 { |
|
580 // Ignore songs not found in MPX DB |
|
581 PRINT1( _L( "MM MTP <> DeleteObjectL deletion failed: %S not found" ), &aFullFileName ); |
|
582 } |
|
583 else if ( err != KErrNone ) |
|
584 { |
|
585 User::Leave( err ); |
|
586 } |
|
587 } |
|
588 |
|
589 // ----------------------------------------------------------------------------- |
|
590 // CMmMtpDpMetadataMpxAccess::RenameRecordL |
|
591 // Rename the filename onto MPX DB |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 void CMmMtpDpMetadataMpxAccess::RenameObjectL( const TDesC& aOldFileName, |
|
595 const TDesC& aNewFileName, |
|
596 TUint aFormatCode ) |
|
597 { |
|
598 PRINT2( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::RenameObjectL aOldFileName = %S, aNewFileName = %S" ), |
|
599 &aOldFileName, &aNewFileName ); |
|
600 |
|
601 TInt err = KErrNone; |
|
602 |
|
603 if ( ( aFormatCode == EMTPFormatCodeAbstractAudioVideoPlaylist ) |
|
604 || ( aFormatCode == EMTPFormatCodeM3UPlaylist ) ) |
|
605 { |
|
606 PRINT( _L( "MM MTP <> Playlist" ) ); |
|
607 TRAP( err, CollectionHelperL()->RenameL( |
|
608 aOldFileName, |
|
609 aNewFileName, |
|
610 EMPXPlaylist ) ); |
|
611 } |
|
612 else // Not a playlist |
|
613 { |
|
614 PRINT( _L( "MM MTP <> Non-Playlist" ) ); |
|
615 TRAP( err, CollectionHelperL()->RenameL( aOldFileName, aNewFileName, EMPXSong ) ); |
|
616 } |
|
617 |
|
618 if ( KErrNotFound == err ) |
|
619 { |
|
620 PRINT1( _L( "MM MTP <> Not found the %S in the MPX DB" ), &aOldFileName ); |
|
621 } |
|
622 else if ( KErrNone != err ) |
|
623 { |
|
624 User::Leave( err ); |
|
625 } |
|
626 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::RenameObjectL" ) ); |
|
627 } |
|
628 |
|
629 // ----------------------------------------------------------------------------- |
|
630 // CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL |
|
631 // Updated object metadata in MPX database |
|
632 // ----------------------------------------------------------------------------- |
|
633 void CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL( const TUint16 aPropCode, |
|
634 const MMTPType& aNewData, |
|
635 const TDesC& aSuid ) |
|
636 { |
|
637 PRINT2( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL aPropCode = 0x%x aSuid = %S" ), |
|
638 aPropCode, |
|
639 &aSuid ); |
|
640 CMPXMedia* media = NULL; |
|
641 |
|
642 // Creat media properties for the song |
|
643 RArray<TInt> contentIDs; |
|
644 CleanupClosePushL( contentIDs ); // + contentIDs |
|
645 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
646 contentIDs.AppendL( KMPXMediaIdAudio ); |
|
647 contentIDs.AppendL( KMPXMediaIdMusic ); |
|
648 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
649 |
|
650 media = CMPXMedia::NewL( contentIDs.Array() ); |
|
651 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
652 CleanupStack::PushL( media ); // + media |
|
653 |
|
654 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
655 KMPXMediaGeneralCategory, |
|
656 EMPXSong ); |
|
657 |
|
658 // MPXMedia default types |
|
659 media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem ); |
|
660 |
|
661 // Get file path |
|
662 TParsePtrC parse( aSuid ); |
|
663 media->SetTextValueL( KMPXMediaGeneralUri, aSuid ); |
|
664 media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
665 |
|
666 TRAPD( err, SetMetadataValueL( aPropCode, aNewData, *media ) ); |
|
667 |
|
668 if ( err == KErrNone ) |
|
669 { |
|
670 SetStorageRootL( parse.Drive() ); |
|
671 |
|
672 // Update the song's metadata with the media object |
|
673 PERFLOGSTART( KMpxCollectionSetL ); |
|
674 CollectionHelperL()->SetL( media ); |
|
675 PERFLOGSTOP( KMpxCollectionSetL ); |
|
676 } |
|
677 else |
|
678 { |
|
679 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL ERROR = %d" ), err ); |
|
680 |
|
681 User::Leave( err ); |
|
682 } |
|
683 |
|
684 CleanupStack::PopAndDestroy( media ); // - media |
|
685 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL" ) ); |
|
686 } |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL |
|
690 // Updated object metadata in MPX database |
|
691 // ----------------------------------------------------------------------------- |
|
692 void CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL( const TUint16 aPropCode, |
|
693 const MMTPType& aNewData, |
|
694 const CMTPObjectMetaData& aObjectMetaData ) |
|
695 { |
|
696 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL aPropCode = 0x%x" ), aPropCode ); |
|
697 CMPXMedia* media = NULL; |
|
698 |
|
699 RArray<TInt> contentIDs; |
|
700 CleanupClosePushL( contentIDs ); // + contentIDs |
|
701 |
|
702 TUint format = aObjectMetaData.Uint( CMTPObjectMetaData::EFormatCode ); |
|
703 if ( ( format == EMTPFormatCodeAbstractAudioVideoPlaylist ) |
|
704 || ( format == EMTPFormatCodeM3UPlaylist ) ) |
|
705 { |
|
706 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL format is playlist" ) ); |
|
707 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
708 |
|
709 media = CMPXMedia::NewL( contentIDs.Array() ); |
|
710 CleanupStack::PushL( media ); // + media |
|
711 |
|
712 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
713 KMPXMediaGeneralCategory, |
|
714 EMPXPlaylist ); |
|
715 } |
|
716 else |
|
717 { |
|
718 // Creat media properties for the song |
|
719 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
720 contentIDs.AppendL( KMPXMediaIdAudio ); |
|
721 contentIDs.AppendL( KMPXMediaIdMusic ); |
|
722 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
723 |
|
724 media = CMPXMedia::NewL( contentIDs.Array() ); |
|
725 CleanupStack::PushL( media ); // + media |
|
726 |
|
727 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
728 KMPXMediaGeneralCategory, |
|
729 EMPXSong ); |
|
730 } |
|
731 |
|
732 // MPXMedia default types |
|
733 media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem ); |
|
734 |
|
735 // Get file path |
|
736 HBufC* suid = aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ).AllocLC(); // + suid |
|
737 TParsePtrC parse( *suid ); |
|
738 media->SetTextValueL( KMPXMediaGeneralUri, *suid ); |
|
739 media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
740 CleanupStack::PopAndDestroy( suid ); // - suid |
|
741 |
|
742 SetMetadataValueL( aPropCode, aNewData, *media ); |
|
743 |
|
744 // Update the song's metadata with the media object |
|
745 PERFLOGSTART(KMpxCollectionSetL); |
|
746 CollectionHelperL()->SetL( media ); |
|
747 PERFLOGSTOP(KMpxCollectionSetL); |
|
748 |
|
749 CleanupStack::PopAndDestroy( 2, &contentIDs ); // - media, contentIDs |
|
750 |
|
751 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL" ) ); |
|
752 } |
|
753 |
|
754 // ----------------------------------------------------------------------------- |
|
755 // CMmMtpDpMetadataMpxAccess::SetMetadataValueL |
|
756 // private, Set property value into MPX object according to property code |
|
757 // ----------------------------------------------------------------------------- |
|
758 void CMmMtpDpMetadataMpxAccess::SetMetadataValueL( const TUint16 aPropCode, |
|
759 const MMTPType& aNewData, |
|
760 CMPXMedia& aMediaProp ) |
|
761 { |
|
762 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetMetadataValueL aPropCode = 0x%x" ), aPropCode ); |
|
763 CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData |
|
764 CMTPTypeArray* desData = NULL; |
|
765 TMTPTypeUint16 uint16Data; |
|
766 TMTPTypeUint32 uint32Data; |
|
767 |
|
768 TMPXAttributeData attrib( MpxAttribFromPropL( aMediaProp, aPropCode ) ); |
|
769 |
|
770 switch ( aPropCode ) |
|
771 { |
|
772 case EMTPObjectPropCodeName: |
|
773 case EMTPObjectPropCodeArtist: |
|
774 case EMTPObjectPropCodeGenre: |
|
775 case EMTPObjectPropCodeAlbumName: |
|
776 case EMTPObjectPropCodeComposer: |
|
777 case EMTPObjectPropCodeAlbumArtist: |
|
778 { |
|
779 PRINT1( _L( "MM MTP <> SetMetadataValueL Before Copy, string length = %d" ), aNewData.Size() ); |
|
780 MMTPType::CopyL( aNewData, *textData ); |
|
781 PRINT1( _L( "MM MTP <> SetMetadataValueL string length = %d" ), textData->StringChars().Length() ); |
|
782 aMediaProp.SetTextValueL( attrib, textData->StringChars() ); |
|
783 HBufC* log = textData->StringChars().AllocL(); |
|
784 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL string = %S" ), log ); |
|
785 delete log; |
|
786 log = NULL; |
|
787 } |
|
788 break; |
|
789 |
|
790 case EMTPObjectPropCodeTrack: |
|
791 { |
|
792 MMTPType::CopyL( aNewData, uint16Data ); |
|
793 TBuf<KMtpMaxStringLength> data; |
|
794 data.AppendNum( uint16Data.Value() ); |
|
795 aMediaProp.SetTextValueL( KMPXMediaMusicAlbumTrack, data ); |
|
796 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL Track = %S" ), &data ); |
|
797 } |
|
798 break; |
|
799 |
|
800 case EMTPObjectPropCodeNumberOfChannels: |
|
801 { |
|
802 MMTPType::CopyL( aNewData, uint16Data ); |
|
803 // Device currently supports types 1(mono) & 2(Stereo) only |
|
804 if ( ( uint16Data.Value() != KMtpChannelMono ) |
|
805 && ( uint16Data.Value() != KMtpChannelStereo ) |
|
806 && ( uint16Data.Value() != 0 ) )// 0 not used |
|
807 { |
|
808 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL NumberOfChannels NOT SUPPORT!" ) ); |
|
809 User::Leave( KErrNotSupported ); |
|
810 } |
|
811 aMediaProp.SetTObjectValueL<TUint32>( KMPXMediaAudioNumberOfChannels, |
|
812 uint16Data.Value() ); |
|
813 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL NumberOfChannels = %u" ), uint16Data.Value() ); |
|
814 } |
|
815 break; |
|
816 |
|
817 case EMTPObjectPropCodeSampleRate: |
|
818 case EMTPObjectPropCodeAudioWAVECodec: |
|
819 case EMTPObjectPropCodeAudioBitRate: |
|
820 case EMTPObjectPropCodeDuration: |
|
821 { |
|
822 MMTPType::CopyL( aNewData, uint32Data ); |
|
823 aMediaProp.SetTObjectValueL<TUint32>( attrib, uint32Data.Value() ); |
|
824 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL uint32 value = %u" ), uint32Data.Value() ); |
|
825 } |
|
826 break; |
|
827 |
|
828 case EMTPObjectPropCodeOriginalReleaseDate: |
|
829 { |
|
830 MMTPType::CopyL( aNewData, *textData ); |
|
831 |
|
832 TBuf<KMtpMaxStringLength> data; |
|
833 data.Copy( textData->StringChars().Left( KMtpDateTimeStringLength ) ); |
|
834 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL 0xDC99 date = %S" ), |
|
835 &data ); |
|
836 if ( data.Length() < KMtpDateTimeStringLength ) |
|
837 { |
|
838 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL 0xDC99 date string is too short" ) ); |
|
839 break; |
|
840 } |
|
841 |
|
842 TLex dateBuf( data.Left( 4 ) ); |
|
843 TInt year; |
|
844 dateBuf.Val( year ); |
|
845 |
|
846 dateBuf = data.Mid( 4, 2 ); |
|
847 TInt month; |
|
848 dateBuf.Val( month ); |
|
849 |
|
850 dateBuf = data.Mid( 6, 2 ); |
|
851 TInt day; |
|
852 dateBuf.Val( day ); |
|
853 |
|
854 dateBuf = data.Mid( 9, 2 ); |
|
855 TInt hour; |
|
856 dateBuf.Val( hour ); |
|
857 |
|
858 dateBuf = data.Mid( 11, 2 ); |
|
859 TInt minute; |
|
860 dateBuf.Val( minute ); |
|
861 |
|
862 dateBuf = data.Mid( 13, 2 ); |
|
863 TInt second; |
|
864 dateBuf.Val( second ); |
|
865 |
|
866 #ifdef _DEBUG |
|
867 RDebug::Print( _L( "MM MTP <> SetMetadataValueL 0xDC99 dateTime Year = %d, Month = %d, Day = %d, Hour = %d, Minute = %d, Second = %d" ), |
|
868 year, month, day, hour, minute, second ); |
|
869 #endif // _DEBUG |
|
870 TDateTime dateTime; |
|
871 if ( ( month > 0 && month < 13 ) |
|
872 && ( day > 0 && day < 32 ) |
|
873 && ( hour >= 0 && hour < 60 ) |
|
874 && ( minute >= 0 && minute < 60 ) |
|
875 && ( second >= 0 && second < 60 ) ) |
|
876 { |
|
877 // microsecond is ignored because MPX doesn't support it, following s60 |
|
878 dateTime.Set( year, |
|
879 TMonth( --month ), |
|
880 --day, |
|
881 hour, |
|
882 minute, |
|
883 second, |
|
884 0 ); |
|
885 } |
|
886 else |
|
887 { |
|
888 // date string syntax is wrong |
|
889 User::Leave( KErrGeneral ); |
|
890 } |
|
891 TTime time( dateTime ); |
|
892 #ifdef _DEBUG |
|
893 RDebug::Print( _L( "MM MTP <> SetMetadataValueL 0xDC99 time = %Ld, Year = %d, Month = %d, Day = %d, Hour = %d, Minute = %d, Second = %d"), |
|
894 time.Int64(), |
|
895 time.DateTime().Year(), |
|
896 time.DateTime().Month(), |
|
897 time.DateTime().Day(), |
|
898 time.DateTime().Hour(), |
|
899 time.DateTime().Minute(), |
|
900 time.DateTime().Second() ); |
|
901 #endif // _DEBUG |
|
902 aMediaProp.SetTObjectValueL( KMPXMediaMusicYear, time.Int64() ); |
|
903 } |
|
904 break; |
|
905 |
|
906 case EMTPObjectPropCodeDescription: |
|
907 { |
|
908 #ifdef __MUSIC_ID_SUPPORT |
|
909 //WriteMusicIdsL(*longString); |
|
910 #else |
|
911 desData = CMTPTypeArray::NewLC( EMTPTypeAUINT16 ); // + desData |
|
912 MMTPType::CopyL( aNewData, *desData ); |
|
913 TUint length = desData->NumElements(); |
|
914 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL length = %d" ), |
|
915 length ); |
|
916 if ( length != 0 ) |
|
917 { |
|
918 TBuf<KMtpMaxDescriptionLength> text; |
|
919 text.Zero(); |
|
920 for ( TUint i = 0; i < length; i++ ) |
|
921 text.Append( desData->ElementUint( i ) ); |
|
922 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL text = %S" ), |
|
923 &text ); |
|
924 aMediaProp.SetTextValueL( KMPXMediaGeneralComment, text ); |
|
925 } |
|
926 else |
|
927 { |
|
928 aMediaProp.SetTextValueL( KMPXMediaGeneralComment, KEmptyText ); |
|
929 } |
|
930 CleanupStack::PopAndDestroy( desData ); // - desData |
|
931 #endif //__MUSIC_ID_SUPPORT |
|
932 } |
|
933 break; |
|
934 |
|
935 case EMTPObjectPropCodeDRMStatus: |
|
936 { |
|
937 MMTPType::CopyL( aNewData, uint16Data ); |
|
938 aMediaProp.SetTObjectValueL<TUint16>( attrib, uint16Data.Value() ); |
|
939 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL DRM Status uint16 value = %u" ), uint16Data.Value() ); |
|
940 } |
|
941 break; |
|
942 |
|
943 default: |
|
944 { |
|
945 User::Leave( KErrNotSupported ); |
|
946 } |
|
947 break; |
|
948 } |
|
949 |
|
950 CleanupStack::PopAndDestroy( textData ); // - textData |
|
951 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetMetadataValueL" ) ); |
|
952 } |
|
953 |
|
954 // --------------------------------------------------------------------------- |
|
955 // CMmMtpDpMetadataMpxAccess::AddSongL |
|
956 // Adds song info to the database |
|
957 // --------------------------------------------------------------------------- |
|
958 // |
|
959 void CMmMtpDpMetadataMpxAccess::AddSongL( const TDesC& aFullFileName ) |
|
960 { |
|
961 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::AddSongL aFullFileName = %S" ), &aFullFileName ); |
|
962 |
|
963 // Does a record already exist for this song? |
|
964 RArray<TInt> contentIDs; |
|
965 CleanupClosePushL( contentIDs ); // + contentIDs |
|
966 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
967 |
|
968 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
969 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
970 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
971 |
|
972 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
973 |
|
974 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
975 |
|
976 searchMedia->SetTextValueL( KMPXMediaGeneralUri, aFullFileName ); |
|
977 |
|
978 RArray<TMPXAttribute> songAttributes; |
|
979 CleanupClosePushL( songAttributes ); // + songAttributes |
|
980 songAttributes.AppendL( KMPXMediaGeneralUri ); |
|
981 |
|
982 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL searchMedia setup with no problems" ) ); |
|
983 |
|
984 PERFLOGSTART(KMpxCollectionFindAllLBeforeAdd); |
|
985 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( |
|
986 *searchMedia, |
|
987 songAttributes.Array() ); |
|
988 PERFLOGSTOP(KMpxCollectionFindAllLBeforeAdd); |
|
989 |
|
990 CleanupStack::PopAndDestroy( &songAttributes ); // - songAttributes |
|
991 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
992 |
|
993 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
994 |
|
995 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
996 { |
|
997 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Not supported KMPXMediaArrayCount" ) ); |
|
998 User::Leave( KErrNotSupported ); |
|
999 } |
|
1000 |
|
1001 TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
1002 |
|
1003 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL %d Media Objects found in the WMP search" ), foundItemCount ); |
|
1004 |
|
1005 if ( foundItemCount > 1 ) |
|
1006 { |
|
1007 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Multiple medias already exist in the collection. Error!!!" ) ); |
|
1008 } |
|
1009 else |
|
1010 { |
|
1011 // Create media properties for the song |
|
1012 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Create media properties" ) ); |
|
1013 RArray<TInt> contentIDs; |
|
1014 CleanupClosePushL( contentIDs ) ; // + contentIDs |
|
1015 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1016 contentIDs.AppendL( KMPXMediaIdAudio ); |
|
1017 contentIDs.AppendL( KMPXMediaIdMusic ); |
|
1018 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
1019 |
|
1020 CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() ); |
|
1021 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1022 CleanupStack::PushL( media ); // + media |
|
1023 |
|
1024 // MPXMedia default types |
|
1025 media->SetTObjectValueL<TMPXGeneralType>( |
|
1026 KMPXMediaGeneralType, |
|
1027 EMPXItem ); |
|
1028 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
1029 KMPXMediaGeneralCategory, |
|
1030 EMPXSong ); |
|
1031 // File Path |
|
1032 // |
|
1033 TParsePtrC parse( aFullFileName ); |
|
1034 media->SetTextValueL( KMPXMediaGeneralUri, aFullFileName ); |
|
1035 media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
1036 |
|
1037 if ( foundItemCount == 0 ) |
|
1038 { |
|
1039 // Set default Metadata |
|
1040 SetDefaultL( *media ); |
|
1041 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Default values set to Media" ) ); |
|
1042 } |
|
1043 |
|
1044 // Update MPX WMP Roundtrip Metadata of the media object |
|
1045 media->SetTObjectValueL<TBool>( KMPXMediaGeneralDeleted, EFalse ); |
|
1046 media->SetTObjectValueL<TBool>( KMPXMediaGeneralModified, EFalse ); |
|
1047 media->SetTObjectValueL<TBool>( KMPXMediaGeneralSynchronized, ETrue ); |
|
1048 media->SetTObjectValueL<TUint>( KMPXMediaGeneralFlags, |
|
1049 KMPXMediaGeneralFlagsIsInvalid | KMPXMediaGeneralFlagsIsCorrupted ); |
|
1050 |
|
1051 if ( foundItemCount == 0 ) |
|
1052 { |
|
1053 PERFLOGSTART(KMpxCollectionAddL); |
|
1054 CollectionHelperL()->AddL( media ); |
|
1055 PERFLOGSTOP(KMpxCollectionAddL); |
|
1056 |
|
1057 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Media added into collection" ) ); |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 PERFLOGSTART(KMpxCollectionSetL); |
|
1062 CollectionHelperL()->SetL( media ); |
|
1063 PERFLOGSTOP(KMpxCollectionSetL); |
|
1064 |
|
1065 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::AddSongL Media metadata updated in collection" ) ); |
|
1066 } |
|
1067 |
|
1068 CleanupStack::PopAndDestroy( media ); // - media |
|
1069 } |
|
1070 |
|
1071 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
1072 |
|
1073 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::AddSongL" ) ); |
|
1074 } |
|
1075 |
|
1076 // ----------------------------------------------------------------------------- |
|
1077 // CMmMtpDpMetadataMpxAccess::AddPlaylistL |
|
1078 // Adds Playlist to Mpx DB |
|
1079 // ----------------------------------------------------------------------------- |
|
1080 // |
|
1081 void CMmMtpDpMetadataMpxAccess::AddPlaylistL( const TDesC& aFullFileName ) |
|
1082 { |
|
1083 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::AddPlaylistL aFullFileName = %S" ), &aFullFileName ); |
|
1084 |
|
1085 // Does a record already exist for this playlist? |
|
1086 RArray<TInt> contentIDs; |
|
1087 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1088 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1089 |
|
1090 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
1091 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1092 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
1093 |
|
1094 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
1095 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1096 searchMedia->SetTextValueL( KMPXMediaGeneralUri, aFullFileName ); |
|
1097 |
|
1098 RArray<TMPXAttribute> playlistAttributes; |
|
1099 CleanupClosePushL( playlistAttributes ); // + playlistAttributes |
|
1100 playlistAttributes.AppendL( KMPXMediaGeneralId ); |
|
1101 playlistAttributes.AppendL( KMPXMediaGeneralTitle ); |
|
1102 playlistAttributes.AppendL( KMPXMediaGeneralUri ); |
|
1103 |
|
1104 PERFLOGSTART(KMpxCollectionFindAllLBeforeAdd); |
|
1105 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( *searchMedia, |
|
1106 playlistAttributes.Array() ); |
|
1107 PERFLOGSTOP(KMpxCollectionFindAllLBeforeAdd); |
|
1108 |
|
1109 CleanupStack::PopAndDestroy( &playlistAttributes ); // - playlistAttributes |
|
1110 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
1111 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
1112 |
|
1113 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
1114 User::Leave( KErrNotSupported ); |
|
1115 |
|
1116 TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
1117 |
|
1118 if ( foundItemCount != 0 ) |
|
1119 { |
|
1120 PRINT( _L( "MM MTP <> Playlist Media already exists in the collection" ) ); |
|
1121 } |
|
1122 else |
|
1123 { |
|
1124 // Creat media properties for the playlist |
|
1125 PRINT( _L( "MM MTP <> Create playlist media properties" ) ); |
|
1126 RArray<TInt> contentIDs; |
|
1127 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1128 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1129 |
|
1130 CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() ); |
|
1131 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1132 CleanupStack::PushL( media ); // + media |
|
1133 |
|
1134 CMPXMediaArray* playlistArray = CMPXMediaArray::NewL(); |
|
1135 CleanupStack::PushL( playlistArray ); // + playlistArray; |
|
1136 |
|
1137 // MPXMedia default types |
|
1138 media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
|
1139 EMPXItem ); |
|
1140 media->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
|
1141 EMPXPlaylist ); |
|
1142 // File Path |
|
1143 // |
|
1144 media->SetTextValueL( KMPXMediaGeneralUri, aFullFileName ); |
|
1145 |
|
1146 TParsePtrC parse( aFullFileName ); |
|
1147 |
|
1148 media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
1149 media->SetTextValueL( KMPXMediaGeneralTitle, parse.Name() ); |
|
1150 media->SetTObjectValueL<TBool>( KMPXMediaGeneralSynchronized, ETrue ); |
|
1151 media->SetCObjectValueL( KMPXMediaArrayContents, playlistArray ); |
|
1152 media->SetTObjectValueL( KMPXMediaArrayCount, playlistArray->Count() ); |
|
1153 |
|
1154 PERFLOGSTART(KMpxCollectionAddL); |
|
1155 CollectionHelperL()->AddL( media ); |
|
1156 PERFLOGSTOP(KMpxCollectionAddL); |
|
1157 |
|
1158 // Clear the array |
|
1159 CleanupStack::PopAndDestroy( playlistArray ); // - playlistArray |
|
1160 |
|
1161 CleanupStack::PopAndDestroy( media ); // - media |
|
1162 } |
|
1163 |
|
1164 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
1165 |
|
1166 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::AddPlaylistL" ) ); |
|
1167 } |
|
1168 |
|
1169 // ----------------------------------------------------------------------------- |
|
1170 // CMmMtpDpMetadataMpxAccess::SetPlaylistL |
|
1171 // Set playlist to DB |
|
1172 // ----------------------------------------------------------------------------- |
|
1173 // |
|
1174 void CMmMtpDpMetadataMpxAccess::SetPlaylistL( const TDesC& aPlaylistFileName, |
|
1175 CDesCArray& aRefFileArray ) |
|
1176 { |
|
1177 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetPlaylistL" ) ); |
|
1178 CMPXMediaArray* playlistArray = CMPXMediaArray::NewL(); |
|
1179 CleanupStack::PushL( playlistArray ); // + playlistArray |
|
1180 |
|
1181 TUint count = aRefFileArray.Count(); |
|
1182 for ( TUint j = 0; j < count; j++ ) |
|
1183 { |
|
1184 // if the file is video, skip it and continue |
|
1185 if ( MmMtpDpUtility::IsVideoL( aRefFileArray[j], iFramework ) ) |
|
1186 { |
|
1187 continue; |
|
1188 } |
|
1189 |
|
1190 // Creat media properties for the song |
|
1191 RArray<TInt> contentIDs; |
|
1192 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1193 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1194 contentIDs.AppendL( KMPXMediaIdAudio ); |
|
1195 contentIDs.AppendL( KMPXMediaIdMusic ); |
|
1196 contentIDs.AppendL( KMPXMediaIdMTP ); |
|
1197 |
|
1198 CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() ); |
|
1199 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1200 CleanupStack::PushL( media ); // + media |
|
1201 |
|
1202 // MPXMedia default types |
|
1203 media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, |
|
1204 EMPXItem ); |
|
1205 media->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, |
|
1206 EMPXSong ); |
|
1207 // File Path |
|
1208 // |
|
1209 TParsePtrC parse( aRefFileArray[j] ); |
|
1210 media->SetTextValueL( KMPXMediaGeneralUri, aRefFileArray[j] ); |
|
1211 media->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
1212 |
|
1213 // Add media into array contents |
|
1214 playlistArray->AppendL( media ); |
|
1215 |
|
1216 CleanupStack::Pop( media ); // - media |
|
1217 } |
|
1218 |
|
1219 RArray<TInt> contentIDs; |
|
1220 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1221 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1222 |
|
1223 CMPXMedia* playlistMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
1224 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1225 CleanupStack::PushL( playlistMedia ); // + playlistMedia |
|
1226 |
|
1227 playlistMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
1228 |
|
1229 playlistMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1230 |
|
1231 playlistMedia->SetTextValueL( KMPXMediaGeneralUri, aPlaylistFileName ); |
|
1232 |
|
1233 TParsePtrC parse( aPlaylistFileName ); |
|
1234 playlistMedia->SetTextValueL( KMPXMediaGeneralDrive, parse.Drive() ); |
|
1235 playlistMedia->SetTObjectValueL<TBool>( KMPXMediaGeneralSynchronized, |
|
1236 ETrue ); |
|
1237 playlistMedia->SetCObjectValueL( KMPXMediaArrayContents, playlistArray ); |
|
1238 playlistMedia->SetTObjectValueL( KMPXMediaArrayCount, |
|
1239 playlistArray->Count() ); |
|
1240 |
|
1241 // Update the duplicate playlist(s) with the new playlist array |
|
1242 PERFLOGSTART(KMpxCollectionSetL); |
|
1243 CollectionHelperL()->SetL( playlistMedia ); |
|
1244 PERFLOGSTOP(KMpxCollectionSetL); |
|
1245 |
|
1246 CleanupStack::PopAndDestroy( playlistMedia ); // - playlistMedia |
|
1247 |
|
1248 // Clear the array |
|
1249 CleanupStack::PopAndDestroy( playlistArray ); // - playlistArray |
|
1250 |
|
1251 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetPlaylistL" ) ); |
|
1252 } |
|
1253 |
|
1254 // --------------------------------------------------------------------------- |
|
1255 // CMmMtpDpMetadataMpxAccess::SetStorageRootL |
|
1256 // Set storage root of the MPX DB |
|
1257 // --------------------------------------------------------------------------- |
|
1258 // |
|
1259 void CMmMtpDpMetadataMpxAccess::SetStorageRootL( const TDesC& aStorageRoot ) |
|
1260 { |
|
1261 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetStorageRoot aStoreRoot = %S" ), &aStorageRoot ); |
|
1262 |
|
1263 // get the drive number |
|
1264 TParse pathParser; |
|
1265 User::LeaveIfError( pathParser.Set( aStorageRoot, NULL, NULL ) ); |
|
1266 TChar driveChar( pathParser.Drive()[0] ); |
|
1267 |
|
1268 TInt driveNumber; |
|
1269 User::LeaveIfError( RFs::CharToDrive( driveChar, driveNumber ) ); |
|
1270 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetStorageRoot drive number = %d" ), driveNumber ); |
|
1271 |
|
1272 // get root path |
|
1273 User::LeaveIfError( PathInfo::GetRootPath( iStoreRoot, driveNumber ) ); |
|
1274 |
|
1275 PRINT1( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetStorageRoot root path: %S" ), &iStoreRoot ); |
|
1276 } |
|
1277 |
|
1278 // --------------------------------------------------------------------------- |
|
1279 // CMmMtpDpMetadataMpxAccess::SetDefaultL |
|
1280 // Sets all of the default media properties |
|
1281 // --------------------------------------------------------------------------- |
|
1282 // |
|
1283 void CMmMtpDpMetadataMpxAccess::SetDefaultL( CMPXMedia& aMediaProp ) |
|
1284 { |
|
1285 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetDefaultL" ) ); |
|
1286 // Title |
|
1287 aMediaProp.SetTextValueL( KMPXMediaGeneralTitle, KNullDesC ); |
|
1288 // Comment |
|
1289 aMediaProp.SetTextValueL( KMPXMediaGeneralComment, KNullDesC ); |
|
1290 // Artist |
|
1291 aMediaProp.SetTextValueL( KMPXMediaMusicArtist, KNullDesC ); |
|
1292 // Album |
|
1293 aMediaProp.SetTextValueL( KMPXMediaMusicAlbum, KNullDesC ); |
|
1294 // Year |
|
1295 //aMediaProp.SetTextValueL(KMPXMediaMusicYear, KNullDesC); // should never set year to KNullDesC, it is a TInt64 value |
|
1296 // Track |
|
1297 aMediaProp.SetTextValueL( KMPXMediaMusicAlbumTrack, KNullDesC ); |
|
1298 // Genre |
|
1299 aMediaProp.SetTextValueL( KMPXMediaMusicGenre, KNullDesC ); |
|
1300 // Composer |
|
1301 aMediaProp.SetTextValueL( KMPXMediaMusicComposer, KNullDesC ); |
|
1302 // Album artFilename |
|
1303 aMediaProp.SetTextValueL( KMPXMediaMusicAlbumArtFileName, KNullDesC ); |
|
1304 // URL |
|
1305 aMediaProp.SetTextValueL( KMPXMediaMusicURL, KNullDesC ); |
|
1306 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetDefaultL" ) ); |
|
1307 } |
|
1308 |
|
1309 TMPXAttributeData CMmMtpDpMetadataMpxAccess::MpxAttribFromPropL( const CMPXMedia& aMedia, |
|
1310 const TUint16 aPropCode ) |
|
1311 { |
|
1312 const TMetadataTable KMetadataTable[] = |
|
1313 { |
|
1314 { EMTPObjectPropCodeName, KMPXMediaGeneralTitle }, |
|
1315 { EMTPObjectPropCodeArtist, KMPXMediaMusicArtist }, |
|
1316 { EMTPObjectPropCodeAlbumName, KMPXMediaMusicAlbum }, |
|
1317 { EMTPObjectPropCodeDateModified, KMPXMediaGeneralDate }, |
|
1318 { EMTPObjectPropCodeDateAdded, KMPXMediaGeneralDate }, |
|
1319 { EMTPObjectPropCodeDuration, KMPXMediaGeneralDuration }, |
|
1320 { EMTPObjectPropCodeTrack, KMPXMediaMusicAlbumTrack }, |
|
1321 { EMTPObjectPropCodeComposer, KMPXMediaMusicComposer }, |
|
1322 { EMTPObjectPropCodeOriginalReleaseDate, KMPXMediaMusicYear }, |
|
1323 { EMTPObjectPropCodeGenre, KMPXMediaMusicGenre }, |
|
1324 { EMTPObjectPropCodeDRMStatus, KMPXMediaMTPDrmStatus }, |
|
1325 { EMTPObjectPropCodeDescription, KMPXMediaGeneralComment }, |
|
1326 { EMTPObjectPropCodeNumberOfChannels, KMPXMediaAudioNumberOfChannels }, |
|
1327 { EMTPObjectPropCodeAudioBitRate, KMPXMediaAudioBitrate }, |
|
1328 { EMTPObjectPropCodeSampleRate, KMPXMediaAudioSamplerate }, |
|
1329 { EMTPObjectPropCodeAudioWAVECodec, KMPXMediaAudioAudioCodec }, |
|
1330 { EMTPObjectPropCodeAlbumArtist, KMPXMediaMusicArtist } |
|
1331 }; |
|
1332 |
|
1333 TInt i = 0; |
|
1334 TInt count = sizeof( KMetadataTable ) / sizeof( KMetadataTable[0] ); |
|
1335 while ( ( KMetadataTable[i].iPropCode != aPropCode ) |
|
1336 && ( i < count ) ) |
|
1337 { |
|
1338 i++; |
|
1339 } |
|
1340 |
|
1341 if ( i == count ) |
|
1342 { |
|
1343 // Not supported by MPX, shouldn't call this function |
|
1344 PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::MpxAttribFromPropL NOT SUPPORTED ATTRIBUTE" ) ); |
|
1345 User::Leave( KErrNotSupported ); |
|
1346 } |
|
1347 |
|
1348 return KMetadataTable[i].iMpxAttrib; |
|
1349 } |
|
1350 |
|
1351 // --------------------------------------------------------------------------- |
|
1352 // CMmMtpDpMetadataMpxAccess::GetAllPlaylistL |
|
1353 // Get all playlists from MPX database in the assigned store |
|
1354 // --------------------------------------------------------------------------- |
|
1355 // |
|
1356 void CMmMtpDpMetadataMpxAccess::GetAllPlaylistL( const TDesC& aStoreRoot, |
|
1357 CMPXMediaArray** aPlaylists ) |
|
1358 { |
|
1359 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllPlaylistL" ) ); |
|
1360 |
|
1361 SetStorageRootL( aStoreRoot ); |
|
1362 |
|
1363 RArray<TInt> contentIDs; |
|
1364 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1365 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1366 |
|
1367 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
1368 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1369 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
1370 |
|
1371 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
1372 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1373 searchMedia->SetTextValueL( KMPXMediaGeneralDrive, iStoreRoot ); |
|
1374 |
|
1375 RArray<TMPXAttribute> playlistAttributes; |
|
1376 CleanupClosePushL( playlistAttributes ); // + playlistAttributes |
|
1377 playlistAttributes.AppendL( KMPXMediaGeneralId ); |
|
1378 playlistAttributes.AppendL( KMPXMediaGeneralTitle ); |
|
1379 playlistAttributes.AppendL( KMPXMediaGeneralUri ); |
|
1380 |
|
1381 PERFLOGSTART(KMpxCollectionGetPlaylist); |
|
1382 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( *searchMedia, |
|
1383 playlistAttributes.Array() ); |
|
1384 PERFLOGSTOP(KMpxCollectionGetPlaylist); |
|
1385 |
|
1386 CleanupStack::PopAndDestroy( &playlistAttributes ); // - playlistAttributes |
|
1387 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
1388 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
1389 |
|
1390 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
1391 { |
|
1392 User::Leave( KErrNotSupported ); |
|
1393 } |
|
1394 |
|
1395 TInt count = *foundMedia->Value<TInt> ( KMPXMediaArrayCount ); |
|
1396 |
|
1397 PRINT1( _L("MM MTP <> CMmMtpDpMetadataMpxAccess::GetAllPlaylistL [%d] playlists found in Playlist Database"), count ); |
|
1398 |
|
1399 if ( count > 0 ) |
|
1400 { |
|
1401 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
1402 { |
|
1403 User::Leave( KErrNotSupported ); |
|
1404 } |
|
1405 |
|
1406 *aPlaylists = CMPXMediaArray::NewL( *( foundMedia->Value<CMPXMediaArray> ( |
|
1407 KMPXMediaArrayContents ) ) ); |
|
1408 } |
|
1409 |
|
1410 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
1411 |
|
1412 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetAllPlaylistL" ) ); |
|
1413 } |
|
1414 |
|
1415 // --------------------------------------------------------------------------- |
|
1416 // CMmMtpDpMetadataMpxAccess::GetAllReferenceL |
|
1417 // Get all references of specified playlist |
|
1418 // --------------------------------------------------------------------------- |
|
1419 // |
|
1420 void CMmMtpDpMetadataMpxAccess::GetAllReferenceL( CMPXMedia* aPlaylist, |
|
1421 CDesCArray& aReferences ) |
|
1422 { |
|
1423 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetAllReferenceL" ) ); |
|
1424 |
|
1425 __ASSERT_DEBUG( aPlaylist, User::Panic( KMtpMpxPanic, KErrArgument ) ); |
|
1426 |
|
1427 // Extract the playlist id from the found object |
|
1428 TUint32 playlistId = *(*aPlaylist).Value<TMPXItemId> ( KMPXMediaGeneralId ); |
|
1429 |
|
1430 // find the media object that contains a list of songs in the playlist |
|
1431 RArray<TInt> contentIDs; |
|
1432 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1433 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1434 |
|
1435 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
1436 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1437 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
1438 |
|
1439 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup ); |
|
1440 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
1441 searchMedia->SetTObjectValueL<TMPXItemId> ( KMPXMediaGeneralId, playlistId ); |
|
1442 |
|
1443 RArray<TMPXAttribute> songAttributes; |
|
1444 CleanupClosePushL( songAttributes ); // + songAttributes |
|
1445 songAttributes.AppendL( KMPXMediaGeneralId ); |
|
1446 songAttributes.AppendL( KMPXMediaGeneralUri ); |
|
1447 |
|
1448 PERFLOGSTART(KMpxCollectionGetReference); |
|
1449 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( *searchMedia, |
|
1450 songAttributes.Array() ); |
|
1451 PERFLOGSTOP(KMpxCollectionGetReference); |
|
1452 |
|
1453 CleanupStack::PopAndDestroy( &songAttributes ); // - songAttributes |
|
1454 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
1455 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
1456 |
|
1457 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
1458 { |
|
1459 User::Leave( KErrNotSupported ); |
|
1460 } |
|
1461 |
|
1462 // Number of references |
|
1463 TInt numOfRefs = *foundMedia->Value<TInt> ( KMPXMediaArrayCount ); |
|
1464 if ( numOfRefs > 0 ) |
|
1465 { |
|
1466 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
1467 { |
|
1468 User::Leave( KErrNotSupported ); |
|
1469 } |
|
1470 |
|
1471 const CMPXMediaArray* refArray = foundMedia->Value<CMPXMediaArray> ( |
|
1472 KMPXMediaArrayContents ); |
|
1473 |
|
1474 // Import the references |
|
1475 for ( TInt i = 0; i < numOfRefs; i++ ) |
|
1476 { |
|
1477 const CMPXMedia* refMedia = ( *refArray )[i]; |
|
1478 |
|
1479 if ( !refMedia->IsSupported( KMPXMediaGeneralUri ) ) |
|
1480 { |
|
1481 User::Leave( KErrNotSupported ); |
|
1482 } |
|
1483 |
|
1484 // may replace the following 3 statements into the following: |
|
1485 // AppendL(refMedia->ValueText(KMPXMediaGeneralUri)); |
|
1486 HBufC* musicFileLocation = refMedia->ValueText( KMPXMediaGeneralUri ).AllocLC(); |
|
1487 aReferences.AppendL( *musicFileLocation ); |
|
1488 |
|
1489 PRINT1( _L("MM MTP <> CMmMtpDpMetadataMpxAccess::GetAllReferenceL, [%S] found from MPX db"), musicFileLocation ); |
|
1490 |
|
1491 CleanupStack::PopAndDestroy( musicFileLocation ); // - musicFileLocation |
|
1492 } |
|
1493 } |
|
1494 |
|
1495 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
1496 |
|
1497 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetAllReferenceL" ) ); |
|
1498 } |
|
1499 |
|
1500 // --------------------------------------------------------------------------- |
|
1501 // CMmMtpDpMetadataMpxAccess::GetPlaylistNameL |
|
1502 // |
|
1503 // --------------------------------------------------------------------------- |
|
1504 // |
|
1505 void CMmMtpDpMetadataMpxAccess::GetPlaylistNameL( CMPXMedia* aPlaylist, |
|
1506 TDes& aPlaylistName ) |
|
1507 { |
|
1508 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetPlaylistNameL" ) ); |
|
1509 |
|
1510 if ( !aPlaylist->IsSupported( KMPXMediaGeneralUri ) ) |
|
1511 { |
|
1512 User::Leave( KErrNotSupported ); |
|
1513 } |
|
1514 |
|
1515 aPlaylistName.Copy( aPlaylist->ValueText( KMPXMediaGeneralUri ) ); |
|
1516 |
|
1517 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetPlaylistNameL" ) ); |
|
1518 } |
|
1519 |
|
1520 // --------------------------------------------------------------------------- |
|
1521 // CMmMtpDpMetadataMpxAccess::GetModifiedContentL |
|
1522 // Get modified content |
|
1523 // --------------------------------------------------------------------------- |
|
1524 // |
|
1525 void CMmMtpDpMetadataMpxAccess::GetModifiedContentL( TInt& arrayCount, |
|
1526 CDesCArray& aModifiedcontent ) |
|
1527 { |
|
1528 PRINT( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::GetModifiedContentL" ) ); |
|
1529 CMPXMedia* foundMedia; |
|
1530 TInt foundItemCount( 0 ); |
|
1531 HBufC* musicFileLocation( NULL ); |
|
1532 |
|
1533 // Modified content |
|
1534 PRINT( _L( "MM MTP <> Modified contents are:" ) ); |
|
1535 |
|
1536 foundMedia = FindWMPMediaLC( KMPXMediaGeneralModified, ETrue ); // + foundMedia |
|
1537 |
|
1538 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
1539 { |
|
1540 User::Leave( KErrNotSupported ); |
|
1541 } |
|
1542 |
|
1543 foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
1544 |
|
1545 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetModifiedContentL() found %d Media Objects" ), foundItemCount ); |
|
1546 |
|
1547 if ( foundItemCount ) |
|
1548 { |
|
1549 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
1550 { |
|
1551 User::Leave( KErrNotSupported ); |
|
1552 } |
|
1553 |
|
1554 const CMPXMediaArray* foundArray = foundMedia->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
1555 |
|
1556 for ( TInt j = 0; j < foundItemCount; j++ ) |
|
1557 { |
|
1558 CMPXMedia* media = CMPXMedia::NewL( *(*foundArray)[j] ); |
|
1559 CleanupStack::PushL( media ); // + media |
|
1560 |
|
1561 if ( !media->IsSupported( KMPXMediaGeneralUri ) ) |
|
1562 { |
|
1563 User::Leave( KErrNotSupported ); |
|
1564 } |
|
1565 |
|
1566 musicFileLocation = media->ValueText( KMPXMediaGeneralUri ).AllocLC(); // + musicFileLoaction |
|
1567 |
|
1568 aModifiedcontent.AppendL( *musicFileLocation ); |
|
1569 arrayCount++; |
|
1570 PRINT1( _L("arrayCount = %d"), arrayCount); |
|
1571 |
|
1572 CleanupStack::PopAndDestroy( musicFileLocation ); // - musicFileLocation |
|
1573 CleanupStack::PopAndDestroy( media ); // - media |
|
1574 } |
|
1575 } |
|
1576 |
|
1577 CleanupStack::PopAndDestroy( foundMedia ); // + foundMedia |
|
1578 PRINT( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::GetModifiedContentL" ) ); |
|
1579 } |
|
1580 |
|
1581 // --------------------------------------------------------------------------- |
|
1582 // CMmMtpDpMetadataMpxAccess::IsExistL |
|
1583 // if the playlsit exist in the MPX DB |
|
1584 // --------------------------------------------------------------------------- |
|
1585 // |
|
1586 TBool CMmMtpDpMetadataMpxAccess::IsExistL( const TDesC& aSuid ) |
|
1587 { |
|
1588 PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::IsExist aSuid(%S)" ), &aSuid ); |
|
1589 RArray<TInt> contentIDs; |
|
1590 CleanupClosePushL( contentIDs ); // + contentIDs |
|
1591 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
1592 |
|
1593 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
1594 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
1595 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
1596 |
|
1597 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
1598 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
1599 searchMedia->SetTextValueL( KMPXMediaGeneralUri, aSuid ); |
|
1600 |
|
1601 RArray<TMPXAttribute> playlistAttributes; |
|
1602 CleanupClosePushL( playlistAttributes ); // + playlistAttributes |
|
1603 playlistAttributes.AppendL( KMPXMediaGeneralId ); |
|
1604 playlistAttributes.AppendL( KMPXMediaGeneralTitle ); |
|
1605 playlistAttributes.AppendL( KMPXMediaGeneralUri ); |
|
1606 |
|
1607 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( *searchMedia, |
|
1608 playlistAttributes.Array() ); |
|
1609 |
|
1610 CleanupStack::PopAndDestroy( &playlistAttributes ); // - playlistAttributes |
|
1611 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
1612 |
|
1613 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
1614 User::Leave( KErrNotSupported ); |
|
1615 |
|
1616 TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
1617 |
|
1618 delete foundMedia; |
|
1619 foundMedia = NULL; |
|
1620 |
|
1621 PRINT1( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::IsExist foundItemCount(%d)" ), foundItemCount ); |
|
1622 return ( foundItemCount > 0 ? ETrue : EFalse ); |
|
1623 } |
|
1624 |
|
1625 //end of file |