|
1 /* |
|
2 * Copyright (c) 2007-2007 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 the License "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: This Class provides the core functionality to Media Management |
|
15 * SAPI Interafce |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <mclfitemlistmodel.h> |
|
22 #include <mclfcontentlistingengine.h> |
|
23 #include <contentlistingfactory.h> |
|
24 #include <mclfsortingstyle.h> |
|
25 |
|
26 |
|
27 #include "mgservice.h" |
|
28 #include "mgpostfilter.h" |
|
29 #include "mgoperationobserver.h" |
|
30 #include "mgclfoperationobserver.h" |
|
31 #include "mgconsts.h" |
|
32 |
|
33 |
|
34 //Media types. |
|
35 _LIT8( KMgMusic ,"Music" ); |
|
36 _LIT8( KMgSound ,"Sound" ); |
|
37 _LIT8( KMgImage ,"Image" ); |
|
38 _LIT8( KMgVideo ,"Video" ); |
|
39 _LIT8( KMgStreamingURL ,"StreamingURL" ); |
|
40 |
|
41 |
|
42 //SortingOrder |
|
43 _LIT8( KMgDescending, "Descending" ); |
|
44 //_LIT8( KMgAscending, "Ascending" ); |
|
45 |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CMgService::NewLC |
|
50 // Returns the instance of CMgService class. |
|
51 // ----------------------------------------------------------------------------- |
|
52 EXPORT_C CMgService* CMgService::NewL() |
|
53 { |
|
54 CMgService* self = new ( ELeave )CMgService(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop( self ); |
|
58 return self; |
|
59 } |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CMgService::~CMgService |
|
62 // Destructor |
|
63 // ----------------------------------------------------------------------------- |
|
64 |
|
65 CMgService::~CMgService() |
|
66 { |
|
67 |
|
68 //release filter class |
|
69 delete iFilter; |
|
70 |
|
71 // release sorting style |
|
72 delete iSortingStyle; |
|
73 |
|
74 // release clf observer class |
|
75 |
|
76 delete iClfObserver; |
|
77 |
|
78 //release iEngine; |
|
79 delete iEngine; |
|
80 |
|
81 |
|
82 } |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CMgService::GetFiles |
|
89 // This function extracts all media item that match the given arguments |
|
90 // ----------------------------------------------------------------------------- |
|
91 |
|
92 EXPORT_C void CMgService::GetListL(const TMgServiceRequest& aInParameters, |
|
93 MMgOperationObserver* aServiceObserver) |
|
94 { |
|
95 |
|
96 //Check if the class is busy or waiting for asynchronous request |
|
97 //This has already been verified by SAPI interface class ,still this condition |
|
98 //is checked keeping in mind that this class may be called directly by a |
|
99 //Series60 application in future |
|
100 if( EMgFree == iState ) |
|
101 { |
|
102 |
|
103 |
|
104 |
|
105 if( NULL != aServiceObserver )//Asynchronous request |
|
106 { |
|
107 // create the instance of CLF list Model for the current request |
|
108 MCLFItemListModel* listModel = iEngine-> |
|
109 CreateListModelLC( *iClfObserver ); |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 SendRequestToClfL( aInParameters.iFileType, |
|
115 aInParameters.iFilterField, |
|
116 aInParameters.iStartVal, |
|
117 aInParameters.iEndVal, |
|
118 aInParameters.iSortField, |
|
119 aInParameters.iOrder, |
|
120 listModel ); |
|
121 |
|
122 CleanupStack::Pop(); |
|
123 |
|
124 iTransactionID = aInParameters.iTransactionID; |
|
125 iClfObserver->SetMemberVar( aInParameters.iTransactionID, |
|
126 aServiceObserver, |
|
127 listModel, |
|
128 this ); |
|
129 |
|
130 |
|
131 |
|
132 } |
|
133 else |
|
134 { |
|
135 //Synchronous request handling is currently not supported |
|
136 User::Leave( KErrNotSupported ); |
|
137 } |
|
138 |
|
139 }//SAPI State |
|
140 else |
|
141 { |
|
142 User::Leave( KErrServerBusy ); // busy in previous request |
|
143 } |
|
144 |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMgService::Cancel |
|
150 // Cancel the pending asynchronous request |
|
151 // ----------------------------------------------------------------------------- |
|
152 EXPORT_C TInt CMgService::CancelL( TUint aTransactionID) |
|
153 { |
|
154 // call cancel of CLF |
|
155 // Right now we are not supporting aTransactionID |
|
156 // but in future we have to find the iClfObserver |
|
157 // coresponding to this Transaction ID and Call cancel |
|
158 // on that observer |
|
159 if( EMgBusy == iState ) |
|
160 { |
|
161 if( aTransactionID == iTransactionID ) |
|
162 { |
|
163 iClfObserver->CancelL( ); |
|
164 Clear(); |
|
165 return KErrNone; |
|
166 } |
|
167 } |
|
168 |
|
169 return KErrArgument; |
|
170 |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CMgService::Clear |
|
175 // It will clear the set filter metadata field ,registered callback |
|
176 // function and sorting fields |
|
177 // ----------------------------------------------------------------------------- |
|
178 |
|
179 void CMgService::Clear() |
|
180 { |
|
181 iFilter->Clear(); |
|
182 iState = EMgFree; |
|
183 iTransactionID = 0; |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CMgService::State |
|
191 // It will return the state of service class. |
|
192 // return EMgFree if it is free and ready to accept |
|
193 // the another request else EMgBusy |
|
194 // ----------------------------------------------------------------------------- |
|
195 EXPORT_C const TMgState& CMgService::State() const |
|
196 { |
|
197 return iState; |
|
198 } |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CMgService::SetSortingField |
|
205 // It will set the metadata field on which the result |
|
206 // should be sorted. |
|
207 // Leave with KErrArgument if aSortField is not valid. |
|
208 // ----------------------------------------------------------------------------- |
|
209 |
|
210 void CMgService::SetSortingFieldL(const TDesC8& aSortField , |
|
211 const TDesC8& aOrder , |
|
212 const RArray<TInt>& aMediaTypes, |
|
213 MCLFItemListModel* alistModel ) |
|
214 { |
|
215 |
|
216 // Default sorting as per file name |
|
217 TCLFDefaultFieldId metaDataId = ECLFFieldIdFileName; |
|
218 TCLFItemDataType metaDataType = ECLFItemDataTypeDesC; |
|
219 |
|
220 //Check If the aSortField is not NULL Descriptor i.e. |
|
221 // sorting metadata is specified |
|
222 |
|
223 if( 0 != aSortField.CompareF( KNullDesC8 ) ) |
|
224 { |
|
225 |
|
226 GetMetaDataIdAndType( aSortField, |
|
227 metaDataId, |
|
228 metaDataType, |
|
229 aMediaTypes ); |
|
230 |
|
231 if( ECLFFieldIdNull == metaDataId ) // check the return type |
|
232 { |
|
233 // The given Sort Field is not supported by Media Management SAPI |
|
234 User::Leave( KErrArgument ); |
|
235 } |
|
236 } |
|
237 |
|
238 iSortingStyle->ResetL(); |
|
239 |
|
240 |
|
241 //Set the field on which sorting has to perform |
|
242 iSortingStyle->AddFieldL( metaDataId ); |
|
243 |
|
244 // Set the sorting field data type |
|
245 iSortingStyle->SetSortingDataType( metaDataType ); |
|
246 |
|
247 if( 0 == aOrder.CompareF( KMgDescending ) ) |
|
248 { |
|
249 iSortingStyle->SetOrdering( ECLFOrderingDescending ); |
|
250 } |
|
251 else if( 0 == aOrder.CompareF( KMgAscending) ) |
|
252 { |
|
253 iSortingStyle->SetOrdering( ECLFOrderingAscending ); |
|
254 } |
|
255 else |
|
256 { |
|
257 User::Leave( KErrArgument ); |
|
258 } |
|
259 |
|
260 //Items with undefined fields are placed after items with defined fields |
|
261 iSortingStyle->SetUndefinedItemPosition( ECLFSortingStyleUndefinedEnd ); |
|
262 |
|
263 // set sorting style in CLF. |
|
264 alistModel->SetSortingStyle( iSortingStyle ); |
|
265 |
|
266 |
|
267 } |
|
268 |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CPostFilter::SetFilterMetaData |
|
272 // Method to set the filter metadata |
|
273 // ----------------------------------------------------------------------------- |
|
274 void CMgService::SetFilterMetaDataL( const TDesC8& aFilterField, |
|
275 const TDesC& aStartVal, |
|
276 const TDesC& aEndVal, |
|
277 const RArray<TInt>& aMediaTypes, |
|
278 MCLFItemListModel* alistModel ) |
|
279 { |
|
280 TCLFDefaultFieldId metaDataId; |
|
281 TCLFItemDataType metaDataType; |
|
282 |
|
283 |
|
284 |
|
285 //Check If the Filter Meta Data is NULL Descriptor, if so |
|
286 // no filtration will be performed |
|
287 if( 0 == aFilterField.CompareF( KNullDesC8 ) ) |
|
288 { |
|
289 metaDataId = ECLFFieldIdNull; |
|
290 metaDataType = ECLFItemDataTypeDesC; // Blank Descriptor |
|
291 iFilter->SetFilterMetaData( metaDataId, metaDataType ); |
|
292 } |
|
293 else |
|
294 { |
|
295 GetMetaDataIdAndType( aFilterField, |
|
296 metaDataId, |
|
297 metaDataType, |
|
298 aMediaTypes); |
|
299 |
|
300 if( ECLFFieldIdNull == metaDataId ) |
|
301 { |
|
302 // The given metaData is not supported by Media Management SAPI |
|
303 User::Leave( KErrArgument ); |
|
304 } |
|
305 |
|
306 |
|
307 iFilter->SetFilterMetaData( metaDataId, metaDataType ); |
|
308 |
|
309 // set filter value of CLF |
|
310 iFilter->SetFilterValueL( aStartVal,aEndVal ); |
|
311 |
|
312 // Set Post Filter in CLF |
|
313 alistModel->SetPostFilter( iFilter ); |
|
314 |
|
315 } |
|
316 |
|
317 } |
|
318 |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CMgService::ConstuctL |
|
322 // It will intialize the underlying CLF(Content Listing Framework) |
|
323 // framework classes and CPostFilter class. |
|
324 // ----------------------------------------------------------------------------- |
|
325 void CMgService::ConstructL() |
|
326 { |
|
327 // create the instance of CLF engine and store it in member data. |
|
328 iEngine = ContentListingFactory::NewContentListingEngineLC(); |
|
329 CleanupStack::Pop(); |
|
330 |
|
331 |
|
332 // create the instance of CPostFilter and store it in member data |
|
333 iFilter = CPostFilter::NewL(); |
|
334 |
|
335 // Get the sorting style from CLF |
|
336 iSortingStyle = ContentListingFactory::NewSortingStyleLC(); |
|
337 CleanupStack::Pop(); |
|
338 |
|
339 //create the instance of clf observer |
|
340 iClfObserver = CClfOperationObserver::NewL(); |
|
341 |
|
342 } |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CMgService::CMgService |
|
349 // Constructor |
|
350 // ----------------------------------------------------------------------------- |
|
351 CMgService::CMgService() |
|
352 : iState( EMgFree ), |
|
353 iEngine( NULL ), |
|
354 iFilter( NULL ), |
|
355 iSortingStyle( NULL ), |
|
356 iClfObserver( NULL ), |
|
357 iTransactionID( 0 ) |
|
358 { |
|
359 |
|
360 } |
|
361 |
|
362 |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // CMgService::SetMediaTypeL |
|
366 // It will convert the aFiletype string into |
|
367 // equivalent Mediatype ID and Fill the Media Type Array |
|
368 // if it is not valid then return KErrNotSupported |
|
369 // ----------------------------------------------------------------------------- |
|
370 void CMgService::SetMediaTypeL (const TDesC8& aFileType, |
|
371 RArray<TInt>& aMediaType) |
|
372 { |
|
373 |
|
374 if( 0 == aFileType.CompareF( KMgMusic ) ) |
|
375 { |
|
376 aMediaType.AppendL( ECLFMediaTypeMusic ); |
|
377 } |
|
378 else if( 0 == aFileType.CompareF( KMgSound ) ) |
|
379 { |
|
380 aMediaType.AppendL( ECLFMediaTypeSound ); |
|
381 } |
|
382 |
|
383 else if( 0 == aFileType.CompareF( KMgImage ) ) |
|
384 { |
|
385 aMediaType.AppendL( ECLFMediaTypeImage ); |
|
386 } |
|
387 |
|
388 else if( 0 == aFileType.CompareF( KMgVideo ) ) |
|
389 { |
|
390 aMediaType.AppendL( ECLFMediaTypeVideo ); |
|
391 } |
|
392 |
|
393 else if( 0 == aFileType.CompareF( KMgStreamingURL ) ) |
|
394 { |
|
395 aMediaType.AppendL( ECLFMediaTypeStreamingURL ); |
|
396 } |
|
397 else |
|
398 { |
|
399 User::Leave ( KErrArgument ); // Media Type Not suuported |
|
400 } |
|
401 |
|
402 } |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CMgService::SendRequestToCLF |
|
410 // This Function will pass the request to CLF frame work for required media type. |
|
411 // return KErrArgument if the FilterMetaData is not Supported |
|
412 // return KErrArgument if the Start Value is not Supported |
|
413 // return KErrArgument if the End Value is mot supported |
|
414 // return KErrNone if sucessful |
|
415 // ----------------------------------------------------------------------------- |
|
416 |
|
417 void CMgService::SendRequestToClfL( const TDesC8& aFileType, |
|
418 const TDesC8& aFilterField, |
|
419 const TDesC& aStartVal, |
|
420 const TDesC& aEndVal, |
|
421 const TDesC8& aSortField, |
|
422 const TDesC8& aOrder, |
|
423 MCLFItemListModel* alistModel ) |
|
424 { |
|
425 |
|
426 |
|
427 |
|
428 RArray<TInt> mediaTypes; |
|
429 CleanupClosePushL( mediaTypes ); |
|
430 |
|
431 //check if it is a valid file type or not |
|
432 SetMediaTypeL( aFileType,mediaTypes ); |
|
433 |
|
434 |
|
435 //set wanted media type in CLF |
|
436 alistModel->SetWantedMediaTypesL( mediaTypes.Array() ); |
|
437 |
|
438 |
|
439 // Set Filter Meta Data and Value |
|
440 SetFilterMetaDataL( aFilterField,aStartVal,aEndVal,mediaTypes,alistModel); |
|
441 |
|
442 |
|
443 |
|
444 // call set sorting field of CLF |
|
445 SetSortingFieldL( aSortField,aOrder,mediaTypes,alistModel ); |
|
446 |
|
447 // set the state = Busy |
|
448 // till this request is complete |
|
449 //which indicates no further request will be taken |
|
450 iState = EMgBusy; |
|
451 |
|
452 //asynchronous call to CLF ECLFRefreshAll |
|
453 alistModel->RefreshL(); |
|
454 |
|
455 |
|
456 CleanupStack::PopAndDestroy( &mediaTypes ); |
|
457 |
|
458 |
|
459 } |
|
460 |
|
461 |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CMgService::GetMetaDataIdAndType |
|
465 // It will convert the aFilterData string into equivalent Metadata ID and Type |
|
466 // which is recognized by underlying framework.(i.e CLF) |
|
467 // ----------------------------------------------------------------------------- |
|
468 void CMgService::GetMetaDataIdAndType(const TDesC8& aMetaData, |
|
469 TCLFDefaultFieldId& aMetaDataId, |
|
470 TCLFItemDataType& aMetaDataType, |
|
471 const RArray<TInt> &aMediaTypes) |
|
472 { |
|
473 //File name field |
|
474 if( 0 == aMetaData.CompareF( KMgFileName )) |
|
475 { |
|
476 aMetaDataType = ECLFItemDataTypeDesC; |
|
477 aMetaDataId = ECLFFieldIdFileName; |
|
478 } |
|
479 |
|
480 |
|
481 |
|
482 // File Extension |
|
483 else if( 0 == aMetaData.CompareF( KMgFileExtension )) |
|
484 { |
|
485 aMetaDataType = ECLFItemDataTypeDesC; |
|
486 aMetaDataId = ECLFFieldIdFileExtension; |
|
487 } |
|
488 |
|
489 |
|
490 // File path field |
|
491 else if( 0 == aMetaData.CompareF( KMgPath )) |
|
492 { |
|
493 aMetaDataType = ECLFItemDataTypeDesC; |
|
494 aMetaDataId = ECLFFieldIdPath; |
|
495 } |
|
496 |
|
497 |
|
498 // File drive field |
|
499 else if( 0 == aMetaData.CompareF( KMgDrive )) |
|
500 { |
|
501 aMetaDataType = ECLFItemDataTypeDesC; |
|
502 aMetaDataId = ECLFFieldIdDrive; |
|
503 } |
|
504 |
|
505 |
|
506 // File size field |
|
507 else if( 0 == aMetaData.CompareF( KMgFileSize )) |
|
508 { |
|
509 aMetaDataType = ECLFItemDataTypeTInt32; |
|
510 aMetaDataId = ECLFFieldIdFileSize; |
|
511 } |
|
512 |
|
513 |
|
514 |
|
515 // File date field |
|
516 else if( 0 == aMetaData.CompareF( KMgFileDate )) |
|
517 { |
|
518 aMetaDataType = ECLFItemDataTypeTTime; |
|
519 aMetaDataId = ECLFFieldIdFileDate; |
|
520 } |
|
521 |
|
522 |
|
523 |
|
524 // Mime type field |
|
525 else if( 0 == aMetaData.CompareF( KMgMimeType )) |
|
526 { |
|
527 aMetaDataType = ECLFItemDataTypeDesC; |
|
528 aMetaDataId = ECLFFieldIdMimeType; |
|
529 } |
|
530 |
|
531 |
|
532 // Full name and path of the file |
|
533 else if( 0 == aMetaData.CompareF( KMgFileNameAndPath )) |
|
534 { |
|
535 aMetaDataType = ECLFItemDataTypeDesC; |
|
536 aMetaDataId = ECLFFieldIdFileNameAndPath; |
|
537 } |
|
538 |
|
539 // Music file song name: and also check If the File type is Music File |
|
540 else if( (0 == aMetaData.CompareF( KMgSongName )) &&( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeMusic )) ) |
|
541 { |
|
542 aMetaDataType = ECLFItemDataTypeDesC; |
|
543 aMetaDataId = ECLFFieldIdSongName; |
|
544 |
|
545 } |
|
546 // Music file artist |
|
547 else if( (0 == aMetaData.CompareF( KMgArtist )) &&( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeMusic )) ) |
|
548 |
|
549 { |
|
550 aMetaDataType = ECLFItemDataTypeDesC; |
|
551 aMetaDataId = ECLFFieldIdArtist; |
|
552 } |
|
553 |
|
554 |
|
555 // Music file album |
|
556 else if((0 == aMetaData.CompareF( KMgAlbum )) && |
|
557 ( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeMusic ) ) ) |
|
558 { |
|
559 aMetaDataType = ECLFItemDataTypeDesC; |
|
560 aMetaDataId = ECLFFieldIdAlbum; |
|
561 } |
|
562 |
|
563 |
|
564 |
|
565 // Music file genre |
|
566 else if((0==aMetaData.CompareF( KMgGenre))&& |
|
567 ( KErrNotFound != aMediaTypes.Find(ECLFMediaTypeMusic) ) ) |
|
568 { |
|
569 aMetaDataType = ECLFItemDataTypeDesC; |
|
570 aMetaDataId = ECLFFieldIdGenre; |
|
571 } |
|
572 |
|
573 |
|
574 |
|
575 // Music file track number |
|
576 else if((0 == aMetaData.CompareF( KMgTrackNumber ))&& |
|
577 ( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeMusic ) ) ) |
|
578 { |
|
579 aMetaDataType = ECLFItemDataTypeTInt32; |
|
580 aMetaDataId = ECLFFieldIdTrackNumber; |
|
581 } |
|
582 |
|
583 |
|
584 |
|
585 // Music file composer |
|
586 else if( (0 == aMetaData.CompareF( KMgComposer )) && |
|
587 ( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeMusic ) ) ) |
|
588 { |
|
589 aMetaDataType = ECLFItemDataTypeDesC; |
|
590 aMetaDataId = ECLFFieldIdComposer; |
|
591 } |
|
592 |
|
593 // Ram link first URL |
|
594 else if( (0 == aMetaData.CompareF( KMgLinkFirstURL )) && |
|
595 ( KErrNotFound != aMediaTypes.Find( ECLFMediaTypeStreamingURL ) ) ) |
|
596 { |
|
597 aMetaDataType = ECLFItemDataTypeDesC; |
|
598 aMetaDataId = ECLFFieldIdRamLinkFirstURL; |
|
599 } |
|
600 |
|
601 else |
|
602 { |
|
603 aMetaDataType = ECLFItemDataTypeTInt32; |
|
604 aMetaDataId = ECLFFieldIdNull; |
|
605 } |
|
606 |
|
607 |
|
608 } |
|
609 |